Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

add a node to a xml node tree - HIERARCHY_REQUEST_ERR

crupperNov 12 2011 — edited Nov 13 2011
I would like to add a new node 'test' between the nodes 'name' and 'address' to an existing node tree. I am getting the following error:
Error in parsing: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.

XML-Code:
<?xml version="1.0" encoding="UTF-8"?>
<order id="1028">  
   <customer>
      <name>Peter M.</name>
      <address>Hohle Gasse 22</address>
      
      <shoes>  
         <name>Air Legend FG/SG</name>  
         <price>135</price>  
      </shoes>
      <shoes>  
         <name>Joggair</name>  
         <price>75</price>  
      </shoes>  
      <shoes>  
         <name>Fechtmeister</name>  
         <price>255</price>  
      </shoes>  
      <shoes>  
         <name></name>  
         <price></price>  
      </shoes>  
   </customer>
</order>
Java-Code:
public void parse (String uri)
   {
      DOMParser parser = new DOMParser();
      try 
      {
          parser.parse(uri);
	  Document doc = parser.getDocument();
          Element element = (Element) doc.getElementsByTagName("shoes").item(0); 
          Element newElement = doc.createElement("test");
          doc.insertBefore(newElement, element);
          ...
I read the documentation, but I have not found the bug. Does anybody have an idea?

Edited by: crupper on Nov 13, 2011 4:21 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2011
Added on Nov 12 2011
1 comment
258 views