Hi,
I try to append one Attribute to each Element in an document.
If I try something like this:
NodeList Elements = document.getElementByTagName("*");
for (int i=0; i<Elements.getLength(); i++){
Attr a = xmldoc.createAttribute("id");
a.setNodeValue(i);
Elements.item(i).append.appendChild((Node) a);
}
I get the following error.
org.w3c.dom.DOMException: DOM006 Hierarchy request error
at org.apache.xerces.dom.ChildAndParentNode.internalInsertBefore
(ChildAndParentNode.java:379)
at org.apache.xerces.dom.ChildAndParentNode.insertBefore
(ChildAndParentNode.java:296)
at org.apache.xerces.dom.NodeImpl.appendChild
(NodeImpl.java:212)
at parsertest.<init>(parsertest.java:36)
at parsertest.main(parsertest.java:44)
Exception in thread "main"
Where do I make the mistake? I think this one should be done easy.
It would be easy if it get an List of Elements instead of a NodeList,
because an Element as the Method setAttribute(). But a Node doesn't have
this Methode.
How can I do this anyway.
Thanks in advance
Matthias