taher chhabrawala
taher chhabrawala

Reputation: 4120

How to add a string array to a node in xml c#

I have a node <name></name> where I put name. Now I want to put an array of names there.

Upvotes: 0

Views: 177

Answers (2)

taher chhabrawala
taher chhabrawala

Reputation: 4120

XmlNode node = xdoc.SelectSingleNode(path);            

foreach(string x in val)
{
    XmlNode subNode = xdoc.CreateNode(XmlNodeType.Element, subNodeName, null);
    subNode.InnerText = x;
    node.AppendChild(subNode);
}

path is the path to the node in xml

Upvotes: 0

Svisstack
Svisstack

Reputation: 16616

If you must put ARRAY to this object you can use some syntax like:

<name>
 <element>X</element>
 <element>Y</element>
</name>

or use a some serialization to string and pack to it.

<name>X,Y</name>

Upvotes: 2

Related Questions