Results 1 to 5 of 5
- 08-18-2008, 11:34 AM #1
Member
- Join Date
- Aug 2008
- Posts
- 3
- Rep Power
- 0
How to parse an xml file using java
Hello frnds,
I am new to java and xml programming.
Now i have to write a java code for searching the xml document with a name and replace that tag value with a new one
how can we do that?
my java program is :
import java.io.FileOutputStream;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import java.util.Properties;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
private void btn_clickmeActionPerformed(java.awt.event.ActionEv ent evt) {
String a = txt_query.getText();
//System.out.println(a);
try
{
OutputStream fout= new FileOutputStream("C:/student.xml");
OutputStream bout= new BufferedOutputStream(fout);
OutputStreamWriter out = new OutputStreamWriter(bout, "8859_1");
out.write("<?xml version=\"1.0\" ");
out.write("encoding=\"ISO-8859-1\"?>\r\n");
out.write("<student>\r\n");
for (int j = 0; j <= 2; j++) {
out.write("<stud_name>" +b[j]);
out.write("</stud_name>\r\n");
out.write("<stud_age>"+n[j]);
out.write("</stud_age>\n");
}
out.write("</student>\r\n");
out.flush(); // Don't forget to flush!
out.close();
}
catch (UnsupportedEncodingException e) {
System.out.println(
"This VM does not support the Latin-1 character set."
);
}
catch (IOException e) {
System.out.println(e.getMessage());
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
//String b[]=;//declaration
//int n
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new student().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btn_clickme;
private javax.swing.JTextField replace;
private javax.swing.JTextField txt_query;
// End of variables declaration
private String b[]={"Suresh","karthik","asldkj"};
private int n[]= {25,26,27};
}
and my xml file is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<student>
<stud_name>Suresh</stud_name>
<stud_age>25</stud_age>
<stud_name>karthik</stud_name>
<stud_age>26</stud_age>
<stud_name>asldkj</stud_name>
<stud_age>27</stud_age>
</student>
Reply soon...........
Thank u all,
Chanti.Last edited by karthik84; 08-18-2008 at 12:41 PM. Reason: Help Urgent
- 08-18-2008, 11:41 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
It's better if you can specifically explain your question here. Because most of the members easy to give a hint depend on that.
- 09-11-2008, 01:20 PM #3
Member
- Join Date
- Jul 2008
- Location
- india
- Posts
- 35
- Rep Power
- 0
use the dom parser to parse the xml file.. it is easy one...
use the api's of dom parser..
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
- 09-11-2008, 01:45 PM #4
Member
- Join Date
- Jul 2008
- Location
- india
- Posts
- 35
- Rep Power
- 0
there are other parsers as well like xalan
- 09-12-2008, 09:38 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
There are lots of parser available for xml passing in Java. Thing here is the question is not specifically explain. If the thread starter not response here for a long, no point keep open this thread.
Similar Threads
-
Parse EDI File Using java
By vaskarbasak in forum Advanced JavaReplies: 6Last Post: 09-24-2008, 02:38 PM -
How to parse the CSV(Comma separation values)file and validate the file using java
By padmajap13 in forum Advanced JavaReplies: 7Last Post: 05-23-2008, 03:46 AM -
SAX Parse
By bluefloyd8 in forum New To JavaReplies: 1Last Post: 01-25-2008, 03:57 PM -
how to parse an xml file
By oregon in forum XMLReplies: 3Last Post: 08-01-2007, 04:53 PM -
How to parse in html
By paty in forum New To JavaReplies: 1Last Post: 07-24-2007, 12:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks