You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Becker, Matthias" <ma...@sap.com> on 2001/02/13 14:27:05 UTC
Append Attribute to Elements (again)
Hi everyone,
one more Question about appending an Attribute to Each Element.
I want to append an Attribute to each Element in an Document.
The created Attributes are not appended to the DOM-Tree.
What is the mistake? A code-example would be great (because i'm a new to
Xerces an DOM-Parsers)
----------------------------------------------------------------------------
---
*
*
----------------------------------------------------------------------------
---
Document xmldoc = parser.getDocument();
NodeList Elements = xmldoc.getElementsByTagName("*");
for (int i=0; i < Elements.getLength(); i++){
String id = new String();
id.valueOf(i);
Attr n = xmldoc.createAttribute("id");
n.setNodeValue(id);
NamedNodeMap attributes = Elements.item(i).getAttributes();
attributes.setNamedItem(n);
}
----------------------------------------------------------------------------
---
*
*
----------------------------------------------------------------------------
---