• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parsing of XML

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
c:oracle: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.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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")
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic