Question

I have XmlNode with some xml tags. And need to wrap this node into two parent tags "" and "". So what I do:

XmlNode newObjectNode = doc.CreateNode(XmlNodeType.Element,"newobject", null);
XmlNode objectNode = doc.CreateNode(XmlNodeType.Element, "objects", null);

newObjectNode.AppendChild(myNode);
objectNode.AppendChild(newObjectNode); 

So I want to have something like:

<objects>
  <newobject>
    my node here
  </newobject>
</objects>

But I have

<newobject>
  <newobject>
    my node here
  </newobject>
</newobject>

What wrong?

Was it helpful?

Solution

maybe

XmlNode objectNode = doc.CreateNode(XmlNodeType.Element, "newobject", null);

->

XmlNode objectNode = doc.CreateNode(XmlNodeType.Element, "objects", null);

OTHER TIPS

the string you are use is newobject for both of the nodes, try this

XmlNode newObjectNode = doc.CreateNode(XmlNodeType.Element,"newobject", null);
XmlNode objectNode = doc.CreateNode(XmlNodeType.Element, "objects", null);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top