aspose file tools*
The moose likes XML and Related Technologies and the fly likes Parsing of XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing of XML" Watch "Parsing of XML" New topic
Author

Parsing of XML

gurusamy sengodan
Ranch Hand

Joined: Oct 13, 2005
Posts: 41
Hi,
Actually I need to parse the following XML.
I have to give "E2B_EXPORT" as input , i should get the id='1'.

String xmlResponseString = � <?xml version="1.0" encoding="UTF-8"?><usl><sch active='true' id='1' nam='E2B_EXPORT' sch-
req='false'><src><db>DB_ARIS_IMP_EXP</db><driver>oracle.jdbc.driver.OracleDriver</driver><url>jdbcracle:thin
:@192.168.103.129:1521:ORCL</url><username>ag511ucagxb1a8</username><password>YWc1MTF1Y2FneGIxYTg=</password><
description>ARIS DB FOR IMPORT
EXPORT</description></src><trg><db>DB_AGX_IMP_EXP</db><driver>oracle.jdbc.driver.OracleDriver</driver><url>jdb
cracle:thin:@192.168.103.129:1521:ORCL</url><username>ag511ucagxb1a8</username><password>YWc1MTF1Y2FneGIxYTg
=</password><description>AGX DB FOR IMPORT EXPORT</description></trg></sch></usl>�;

while parsing I have to give "E2B_EXPORT" as input , i should get the id='1'.
How to do it. It's very urgent.

Thanks in Advance.
Dhanya Palanisamy
Ranch Hand

Joined: Oct 20, 2006
Posts: 61
Hi,

First you have chhose a parser to parse the XML. Here is a small example.

DOMParser parser = new DOMParser();
Reader in = new BufferedReader(new FileReader("xml file "));
InputSource input = new org.xml.sax.InputSource(in);
parser.parse(input);
Document doc = parser.getDocument();
Element rootElement= doc.getDocumentElement();
root = new DefaultMutableTreeNode(rootElement.getNodeName));

// root will have the root element of your XML. From that you can move down or compare and get your id using getAttribute("attribute_name") function

Hope this helps
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
make a DOM out of the xml.Using xPath get the node which has the name attribure as E2B_EXPORT.
Like //sch[@nam='E2B_EXPORT']
now query the node for id attribute using node.getAttribute("ID")


Rahul Bhattacharjee
LinkedIn - Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing of XML