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