The format of the XML file to be generated is as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Update>
<Soft name = "blogwriter">
<Verson> 1.0.1.2 </Verson>
<Download> http://www.csdn.net/BlogWrite.rar </download>
</Soft>
</Update>
Detailed code:
Xmldocument Doc = new xmldocument ();
Xmldeclaration dec = Doc. createxmldeclaration ("1.0", "UTF-8", null );
Doc. appendchild (DEC );
// Create a root node (level 1)
Xmlelement root = Doc. createelement ("Update ");
Doc. appendchild (Root );
// Create a node (level 2)
Xmlnode node = Doc. createelement ("soft ");
Node. Attributes. append (createattribute (node, "name", "blogwriter "));
// Create a node (level 3)
Xmlelement element1 = Doc. createelement ("Verson ");
Element1.innertext = "1.0.1.2 ";
Node. appendchild (element1 );
Xmlelement element2 = Doc. createelement ("Download ");
Element2.innertext = "http://www.csdn.net/BlogWrite.rar ";
Node. appendchild (element2 );
Root. appendchild (node );
Doc. Save (@ "C: \ WEB \ BB. xml ");
Console. Write (Doc. outerxml );
Add node attributes
Public xmlattribute createattribute (xmlnode node, string attributename, string value)
{
Try
{
Xmldocument Doc = node. ownerdocument;
Xmlattribute ATTR = NULL;
ATTR = Doc. createattribute (attributename );
ATTR. value = value;
Node. Attributes. setnameditem (ATTR );
Return ATTR;
}
Catch (exception ERR)
{
String DESC = err. message;
Return NULL;
}
}
The namespace to be added is using system. xml;