我有一些带有一些xml标签的XmlNode。并且需要将此节点包装成两个父标签“”和“”。所以我做了什么:
XmlNode newObjectNode = doc.CreateNode(XmlNodeType.Element,"newobject", null);
XmlNode objectNode = doc.CreateNode(XmlNodeType.Element, "objects", null);
newObjectNode.AppendChild(myNode);
objectNode.AppendChild(newObjectNode);
所以我希望有类似的东西:
<objects>
<newobject>
my node here
</newobject>
</objects>
但我有
<newobject>
<newobject>
my node here
</newobject>
</newobject>
有什么不对?
答案 0 :(得分:2)
也许
XmlNode objectNode = doc.CreateNode(XmlNodeType.Element, "newobject", null);
- &GT;
XmlNode objectNode = doc.CreateNode(XmlNodeType.Element, "objects", null);
答案 1 :(得分:0)
对于newobject
,您使用的字符串为nodes
,请尝试此
XmlNode newObjectNode = doc.CreateNode(XmlNodeType.Element,"newobject", null);
XmlNode objectNode = doc.CreateNode(XmlNodeType.Element, "objects", null);