locked
how to create xml element using for loop only changing text inside RRS feed

  • Question

  • User1081274538 posted

    suppose i want to create xml like this

    <items>

    <item>text1</item>

    <item>text2</item>

    <item>text3</item>

    <item>text4</item>

    <items>

    getting text1,text2.... dynamically.

     To append item to items we use following code:

    newel=xmlDoc.createElement("item");

    x=xmlDoc.getElementsByTagName("items")[0];

    txt =xmlDoc.createTextNode("text1");

    newel.appendChild(txt);


    x.appendChild(newel);


    now how to this process dynamically for 4 items


    please help me....Thanks in advance.

    Thursday, April 18, 2013 8:01 AM

All replies

  • User1938476581 posted

    Hi,

    try this

    for (int i = 1; i < 5; i++)
           {
                          
               // Create <item> Node
               XmlElement environmentElement = docConfig.CreateElement("item");
               XmlText environText = docConfig.CreateTextNode("text"+i);
               environmentElement.AppendChild(environText);
               docConfig.ChildNodes.Item(0).AppendChild(environmentElement);
           }

    and please refer resolved thread

    http://www.codeproject.com/Questions/407003/Create-XML-Dynamically-using-Asp-net-Csharp

    Hope it can help u

    Thursday, April 18, 2013 11:09 PM
  • User1081274538 posted

    Actually i wanted do this using Javascript

    Friday, April 19, 2013 8:21 AM