Skip to content

Generate xml using c#

murali

Asked Jun 16, 2008, 10:18 PM EDT7 answers
Share
LinkedInX
Hi people!
i need to generate an xml using c#.net.how am i supposed to do,give me an example.
As i am a new comer for.Net.Try to explain me with crisp and clear.
Hope i get a best possible solution.

7 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    I find it is actually easiest to just make a big string and fill it manually and use the XmlDocument.Load(string) function to get the actual XML part out if you need it. But usually when making the XMl file, it is for saving, as a string essentially, so why not just make it as a string. When reading it in, let the load function do the dirty work.
    0
  • 0
    Hello friend!Thanks for the reply but as i told already i am a new comer to .Net so please explain me with an example and try to give the coding
    0
  • Bechir Bejaoui
    0
    Ok my freind try this

    Java
    XmlDataDocument myDoc = new XmlDataDocument();
    XmlElement E1 = myDoc.CreateElement("Element1");
    
    XmlAttribute att1 = myDoc.CreateAttribute("attribute1");
    XmlAttribute att2 = myDoc.CreateAttribute("attribute2");
    att1.value = "value1";
    att2.value = "value2";
    E1.attributes.append(att1);
    E1.attributes.append(att2);
    myDoc.appendchild(E1);
    myDoc.save(@"C:\myFile.xml");

    excute the code and brwose to the path C:\myFile.xml and see what happens

    This technology is called DOM document object model

    0
  • 0
    Thanks a lot!I understood.
    i have generated an xml but fully hard code.Like
    start element many child's and for that child i have sub-childs and end element.
    so coding goes on and on.
    Initially i want to take the worksheet names from an excel and column names and values from the excel.i have mentioned all the columns for getting the column names.I guess this is hard code.how can i simplify this.I guess you all understood.
    thanks to all the friends in advance.
    0