Wednesday, April 18, 2007

Using .NET to Build a XML DOM

XmlDocument xmldoc = new XmlDocument();

XmlDeclaration xmldec = xmldoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");


xmldoc.InsertBefore(xmldec, xmldoc.DocumentElement);


XmlElement xmluser = xmldoc.CreateElement("userdata");

xmldoc.DocumentElement.PrependChild(xmluser);


XmlElement name = xmldoc.CreateElement("name");

name.AppendChild(xmldoc.CreateTextNode("abc123"));

xmluser.AppendChild(name);

 

XmlElement id = xmldoc.CreateElement("id");

id.AppendChild(xmldoc.CreateTextNode("A100000000"));

xmluser.AppendChild(id);

No comments: