更改XmlElement Name属性 [英] change XmlElement Name property
本文介绍了更改XmlElement Name属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在c ++ / cli中更改XmlElement的Name属性。
I would like to change the Name property of an XmlElement in c++/cli.
我想做 myXmlElem.Name = xyz
,但是编译器告诉我,我无法对Name属性进行设置操作。
I would like to do myXmlElem.Name = "xyz"
, but the compiler tells me that I can't do a set operation on the Name property.
ie
<abc/>
已更改为
<xyz/>
如何实现?
谢谢!
推荐答案
您不能像这样更改XmlElement的Name属性(Name是只读的)。
you can't change the Name property of an XmlElement like that (Name is read only).
但是您可以执行以下操作(以C#为例)。
you can however do something like the following (example in C#).
XmlElement xyz = myXmlElem.OwnerDocument.CreateElement("xyz");
myXmlElem.ParentNode.ReplaceChild(xyz, myXmlElem);
编辑以回应您的评论
XmlElement xyz = myXmlElem.OwnerDocument.CreateElement("xyz");
for(int i = 0; i < myXmlElem.ChildNodes.Count; i++){
XmlNode child = myXmlElem.ChildNodes[i];
xyz.AppendChild(child.CloneNode(true));
}
myXmlElem.ParentNode.ReplaceChild(xyz, myXmlElem);
这篇关于更改XmlElement Name属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文