C#createxml
学习xml笔记,核心代码片段,测试结果在附件xml文件中.
- 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
陕西网站建设公司成都创新互联公司,陕西网站设计制作,有大型网站制作公司丰富经验。已为陕西成百上千家提供企业网站建设服务。企业网站搭建\成都外贸网站制作要多少钱,请找那个售后服务好的陕西做网站的公司定做!
附件:http://down.51cto.com/data/2358789
当前文章:C#createxml
文章转载:http://azwzsj.com/article/gcijhj.html