• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

get data from Document object

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
I am using Crimson parser to parse xml.
My xml:
******************************
<root>
<aaa>
<bbb>
<info>bbb information</info>
</bbb>
<info>aaa information</info>
</aaa>
</root>
*********************************
After parsing this xml I have Document object;
Can you tell me how can I get "aaa information" from Document object not "bbb information"?
Thank you.
Andrew Sljusar.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andrew,
There are two ways of getting this information.
1. Using the DOM APIs
2. Using the XPath APIs
Example using DOM:

Example using XPath (requires XALAN):

Cheers
 
Andrew Sljusar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
But if my xml has the following structure:
******************************
<root>
<aaa>
<info>aaa information</info>
<bbb>
<info>bbb information</info>
</bbb>
</aaa>
</root>
*********************************
then this code returns: "bbb information"
NodeList infoNodeList = doc.getElementsByTagName("info");
Element info = (Element) infoNodeList.item(1);
Text text = (Text) info.getFirstChild();
String aaaInformation = text.getNodeValue();
How can I get data from "/root/aaa/info" not from "/root/aaa/bbb/info" using DOM Api?
regards,
Andrew Sljusar
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
shouldn't that be infoNodeList.item(0) instead of (1) ?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic