• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parse out entire XML Node (contains child nodes) from InputStream  RSS feed

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a total newbie on dealing with XML like this, so am not even sure where to begin to try and read up on this and I am on a massive time crunch.

I have a chunk of XML that I need to take out of file that I am getting from an inputStream. I already have some code working to get the data of a single node, so I do already have code with the following which creates a Document object from my inputstream:


So, I am trying to figure out now, how do I loop through something like

So that I can write a particular chunk of the XML data (i.e. specify the root node name and get all the child nodes) back out to a file? I assume I can utilize the myDOM variable I have (org.w3c.dom.Document) to possibly create a nodelist, but I am just having troubles figuring out how to really do this??

Thank you,

Jennifer
[ March 09, 2007: Message edited by: Jennifer Bhamoo ]
 
Sheriff
Posts: 22951
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have to loop through anything. You don't have to write your own code at all. You just create an identity transformation and ask it to convert your Document object to text. Something like this:
 
Jennifer Bhamoo
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

I probably should have written that I am dealing with an XDP file (basically an XML plus PDF file), so I need to extract out the chunk containing my XML data. I could do each form field (i.e. element) seperately, but I didn't really need to do that, I just need the entire root node and all the child elements.

Thanks!
 
Paul Clapham
Sheriff
Posts: 22951
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So you have an XML document (an XDP file is an XML document). You already know how to read it, as you said in your original post. And I showed you how to write it, or any subtree of it, in my response. So all that is left is this:

I need to extract out the chunk containing my XML data

So I assume you are having trouble finding that chunk. Is that right?
 
Jennifer Bhamoo
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. ok, I understand better what you wrote earlier. So, my question is, how do I get just that one node? I tried a few things and got no where.
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can either use the org.w3c.dom methods to walk through the DOM till you find the node or one of the convenience APIs that have been created to make this easier such as XPath.
I recently wrote this survey article on the XPath API that is part of the Java 1.5 release.

E. R. Harold's chapter on XPath is an excellent tutorial.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!