Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding an child node from a nodelist.

 
Jon Bricker
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21299
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic