问题描述
基本上我需要的是能够重命名 XmlElement(这在 .NET afaik 中是不可能的).
Basicly what I need is to be able to rename an XmlElement (which is not possible in .NET afaik).
有没有办法将一个 XmlElement 导入节点并重命名这个新的 XmlElement?
Is there a way to ImportNode an XmlElement and rename that new XmlElement?
XmlElement oldElm;XmlDocument 文档;XmlElement newElm = (XmlElement) doc.ImportNode(oldElm, true);newElm.Rename("newElmName", "urn:newElmNameSpace");
XmlElement oldElm;XmlDocument doc;XmlElement newElm = (XmlElement) doc.ImportNode(oldElm, true);newElm.Rename("newElmName", "urn:newElmNameSpace");
或类似的东西...
我想避免的是编写一个循环,将子节点导入到新创建的元素中...
What I want to avoid is to write a loop where I import the childnodes into a newly created element...
这可能吗(在 .NET 中)?
Is this possible (in .NET)?
推荐答案
我认为目前在 .NET 中使用 XmlDocument 是不可能的.据我所知并且已经能够研究实现元素重命名的唯一方法是创建一个新元素并将原始元素移动到该元素下.
I don't think that this is possible in .NET at the moment using the XmlDocument. From what I know and have been able to research the only way to achieve a re-naming of an element is to create a new element and move the origional elements children under this element.
这是一个示例,向您展示了如何使用W3C DOM (XmlDocument) 模型通过移动子项.
Here is an example showing you how to re-name an element using the W3C DOM (XmlDocument) model by moving the children.
这篇关于.NET:导入具有不同元素名称的 XmlElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!