aspose file tools*
The moose likes XML and Related Technologies and the fly likes Adding an child node from a nodelist. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Adding an child node from a nodelist." Watch "Adding an child node from a nodelist." New topic
Author

Adding an child node from a nodelist.

Jon Bricker
Greenhorn

Joined: Feb 28, 2003
Posts: 23
I need to add new elements to a XML document. The elements are being built while looping through a DB result. Each node will have multiple elements added to it but
just 1 level of children.

I'm using XPath to find all of my nodes then creating an element and using append child to the current node in the NodeList. This is not working. what other options
do I have? I would rather not build it as I go but it may be my only choice.

initial XML


Expected XML at the end


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

So what "isn't working" about that code? It looks okay to me.

(You do have code which writes the DOM out to a file somewhere, don't you?)
Jon Bricker
Greenhorn

Joined: Feb 28, 2003
Posts: 23
Paul Clapham wrote:So what "isn't working" about that code? It looks okay to me.

(You do have code which writes the DOM out to a file somewhere, don't you?)


I'm writing out the result when I run the unit test. That code produces no changes to the document


Jon Bricker
Greenhorn

Joined: Feb 28, 2003
Posts: 23
I'm not happy with how I solved it so I would still like to see what I was doing wrong with editing the document using XPath. It seems very clunky I keep thinking that I'm missing a line of code so the edits would take.



Those changes given this input:



will produce this
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding an child node from a nodelist.