//各位还是不要克隆,看看下面,谢谢上面的两位星星!
procedure ReNameNodeByPathString(XMLDOC: IXMLDOMDocument; PathStr, NewName: String);
var
i: Integer;
Attributes: IXMLDOMNamedNodeMap;
SpecXMLNode, NewXMLNode: IXMLDOMNode;
begin
SpecXMLNode:=XMLDOC.selectSingleNode(PathStr);
if SpecXMLNode <> nil then
begin
NewXMLNode:=XMLDOC.createNode(NODE_ELEMENT,NewName,'');
Attributes:=(SpecXMLNode as IXMLDOMElement).attributes;
for i := 0 to Attributes.length - 1 do
(NewXMLNode as IXMLDOMElement).setAttribute(Attributes.item[i].nodeName,Attributes.item[i].nodeValue);
SpecXMLNode:=SpecXMLNode.parentNode.replaceChild(NewXMLNode,SpecXMLNode);
while SpecXMLNode.childNodes.length <> 0 do
NewXMLNode.appendChild(SpecXMLNode.removeChild(SpecXMLNode.childNodes.item[0]));
xns:=srcxn.CloneNode(true); // copy node to save node info
srcxn.ParentNode.ChildNodes.Remove(oldxn); // delete the node
targetxn.ChildNodes.Add(xns); // add node to target node