Showing posts with label XML How to add extra values in one attribute?. Show all posts
Showing posts with label XML How to add extra values in one attribute?. Show all posts

How to add extra values in one attribute?

Saturday, October 3, 2015

I want to add so many values in one attribute. Below is my code,

        XmlDocument doc = new XmlDocument();
        XmlElement root = doc.CreateElement("root");
        doc.AppendChild(root);
        XmlElement mainelement;
        mainelement = doc.CreateElement("main_element");
        root.AppendChild(mainelement);
        string[] array = new string[] { "one", "two", "three" };
        for (int i = 0; i < 3; i++)
        {
            XmlElement subelement = doc.CreateElement("shop");
            subelement.SetAttribute("Name", "");
            subelement.SetAttribute("client", array[i]);
            mainelement.AppendChild(subelement);
        }
         doc.Save(@"C:\simple.xml");

It gives output like,

<root>
  <main_element>
    <shop Name="" client="one" />
    <shop Name="" client="two" />
    <shop Name="" client="three" />
  </main_element>
</root>

but my expected output is

<root>
  <main_element>
    <shop Name="" client="one,two,three" />
  </main_element>
</root>

help me for do changes like this. Thanks in advance.