- 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's 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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。