You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "DAWSON,DEVON (HP-Roseville,ex1)" <de...@hp.com> on 2001/01/06 00:35:16 UTC
Renaming elements
Hello all,
Sorry for asking what is probably a bone-head question but I'm just getting
into Xerces and can't find the answer myself.
My question is - Is it possible to change the tag name of an element after
it is instantiated? I'm parsing one document and creating another from
clones of certain encountered elements, but I need to change the tag names
for the second document. Is this doable and if so, how? Or, put another
way, how would you do the above?
Thanks
Devon Dawson
Hewlett-Packard
NIS R&D Lab
RE: Renaming elements
Posted by Jay Cain <ja...@cett.msstate.edu>.
Devon,
You cannot rename an element, or an attribute for that matter. Probably the
simplest way to rename an element is to create the new element, then loop
through the child and attribute nodes and add them to the new element (after
importing them if the the documents are different). Here is an example
method:
void renameElement(Element from, Element to) {
Document toDoc = to.getOwnerDocument();
// Copy attribute nodes.
NamedNodeMap fromAttrs = from.getAttributes();
int index;
for (index = 0; index < fromAttrs.getLength(); index++) {
to.setAttribute((Attr)toDoc.importNode(fromAttrs.item(index), false));
}
// Copy child nodes.
Node fromChild = from.getFirstChild();
while (fromChild != null) {
to.appendChild(toDoc.importNode(fromChild, true));
fromChild = fromChild.getNextSibling();
}
}
- - - - -
Jay Cain
Center for Educational and Training Technology
Mississippi State University
-----Original Message-----
From: DAWSON,DEVON (HP-Roseville,ex1) [mailto:devon_dawson@hp.com]
Sent: Friday, January 05, 2001 5:35 PM
To: xerces-j-dev@xml.apache.org
Subject: Renaming elements
Hello all,
Sorry for asking what is probably a bone-head question but I'm just getting
into Xerces and can't find the answer myself.
My question is - Is it possible to change the tag name of an element after
it is instantiated? I'm parsing one document and creating another from
clones of certain encountered elements, but I need to change the tag names
for the second document. Is this doable and if so, how? Or, put another
way, how would you do the above?
Thanks
Devon Dawson
Hewlett-Packard
NIS R&D Lab
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org