Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes Parsing XML with JAXP 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 XML with JAXP" Watch "Parsing XML with JAXP" New topic
Author

Parsing XML with JAXP

Rick Crawford
Ranch Hand

Joined: Aug 17, 2001
Posts: 34
Hello all. Could someone kindly post some code to show me how to parse the following example XML data (read in from a string?)
<?xml version="1.0" ?>
<FORMDATA>
<BILLING>
<INVOICENO>1111111</INVOICENO>
<CUSTOMERNO>ABC123</CUSTOMERNO>
</BILLING>
</FORMDATA>
I'm using the JAXP parser. The document seems to be parsing okay, as I can System.out.println doc.getDocumentElement() and see the entire XML stream.
Here's the code I've got so far, which isn't much:

I'm after the value of the INVOICENO and CUSTOMERNO. Is there some sort of way to access the value of these elements by XML tag names?
Thanks in advance for the help,
Rick <><
Rob Bass
Ranch Hand

Joined: Aug 28, 2001
Posts: 67
Use Xalan to query the DOM Tree
Palani kumar
Greenhorn

Joined: Sep 01, 2001
Posts: 12
Hei
after parsing you can take the values by getting to the node
you can take this by using the method
NodeList nl = Document.getElementsByTagName("INVOICENO");
as shown above this gives all the elements with the said name.
Node invoice= nl.item(0); \\this gives you the code the value '0' denotes the first element
Node value = invoice.getFirstChild(); \\this gives the text node from where you can take the value
String s = value.getNodeValue();
Hope this helps
Cheers
:-)
Palanikumar
------------------
In the end everything is Right,If it's not then It's not the End


In the end everything is Right,If it's not then It's not the End
 
 
subject: Parsing XML with JAXP