Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with adding an XML node to an existent XML File

 
Hugo Alberto Bedolla
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a problem when trying to write a new node to an xml file, basically the new node isn't appended to the file. I tried to write to another file, but in both cases, only the old data appears... what am I doing wrong? :S


Here's my code:

Thanks in advance.

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try appending the XmlDataElement created to the document.
 
Hugo Alberto Bedolla
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Jai wrote:Try appending the XmlDataElement created to the document.


Thanks for your reply... done, I got:

org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:391)
at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:235)


Code is (look around line 35):
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then try where you have to append the XmlDataElement. If that should be under the root, then get the doc.getDocumentElement() and append the XmlDataElement to it.
 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See also this duplicate thread.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48985
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:See also this duplicate thread.
Which is in a far more appropriate location. Thank you for noticing, Rob. I am moving this thread.
 
Hugo Alberto Bedolla
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Jai wrote:Then try where you have to append the XmlDataElement. If that should be under the root, then get the doc.getDocumentElement() and append the XmlDataElement to it.


Hi John: Fine, that works; I was deducing when I call "Element XmlDataElement = doc.createElement("XmlData");" DOM knows both is a new node, and where I wanna put the new node (considering is the next new node inside the document) but it is not the case. Here's the new code calling the root node and appending a new XmlData node to it, that solution worked for me (Lines 34, 35):

Again, thanks so much for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic