File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing of XML

 
gurusamy sengodan
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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")
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic