The following is the core generation segment, which is included in the xml file of the attachment.
XmlDocument xmlDocument = new XmlDocument (); // create xml document
XmlNode xmlNode = xmlDocument. CreateNode (XmlNodeType. XmlDeclaration, "", ""); // xml document header declaration
XmlDocument. AppendChild (xmlNode); // add xml document header declarations
XmlElement xmlElement = xmlDocument. CreateElement ("", "TestDataModels", ""); // create xml root node
XmlElement element = xmlDocument. CreateElement ("", "TestDataModels", ""); // create TestDataModels 'child node
For (int I = 1; I <6; I ++)
{
XmlElement element = xmlDocument. CreateElement ("", "TestDataModels", ""); // create TestDataModels 'child node
// Add child node for the TestDataModels node
XmlElement elementCode = xmlDocument. CreateElement ("Test", "Code ","");
XmlText xmlTextCode = xmlDocument. CreateTextNode (tm. TCode );
ElementCode. AppendChild (xmlTextCode );
Element. AppendChild (elementCode );
XmlElement elementName = xmlDocument. CreateElement ("Test", "Name ","");
XmlText xmlTextName = xmlDocument. CreateTextNode (tm. TName );
ElementName. AppendChild (xmlTextName );
Element. AppendChild (elementName );
// TestType start
XmlElement elementType = xmlDocument. CreateElement ("Test", "Type ","");
XmlElement elementTypeCode = xmlDocument. CreateElement ("Type", "TCode ","");
XmlText xmlTextTypeCode = xmlDocument. CreateTextNode (tt. TtCode );
ElementTypeCode. AppendChild (xmlTextTypeCode );
ElementType. AppendChild (elementTypeCode );
XmlElement elementTypeName = xmlDocument. CreateElement ("Type", "TName ","");
XmlText xmlTextTypeName = xmlDocument. CreateTextNode (tt. TtName );
ElementTypeName. AppendChild (xmlTextTypeName );
ElementType. AppendChild (elementTypeName );
Element. AppendChild (elementType );
// TestType end
XmlElement. AppendChild (element); // For xmlElement add child element
}
XmlDocument. AppendChild (xmlElement); // For xmlDocument add child node
XmlDocument. Save (dataFile); // save the xmlDocument
This article is from the "Wolf soul" blog