C# create xml
XmlDocumentxmlDocument=newXmlDocument();//createxmldocumentXmlNodexmlNode=xmlDocument.CreateNode(XmlNodeType.XmlDeclaration,"","");//xmldocumentheaderdeclarationxmlDocument.AppendChild(xmlNode);//addxmldocumentheaderdeclarationsXmlElementxmlElement=xmlDocument.CreateElement("","TestDataModels","");//createxmlrootnodeXmlElementelement=xmlDocument.CreateElement("","TestDataModels","");//createTestDataModels'childnodefor(inti=1;i<6;i++){XmlElementelement=xmlDocument.CreateElement("","TestDataModels","");//createTestDataModels'childnode//addchildnodefortheTestDataModels'snodeXmlElementelementCode=xmlDocument.CreateElement("Test","Code","");XmlTextxmlTextCode=xmlDocument.CreateTextNode(tm.TCode);elementCode.AppendChild(xmlTextCode);element.AppendChild(elementCode);XmlElementelementName=xmlDocument.CreateElement("Test","Name","");XmlTextxmlTextName=xmlDocument.CreateTextNode(tm.TName);elementName.AppendChild(xmlTextName);element.AppendChild(elementName);//testTypestartXmlElementelementType=xmlDocument.CreateElement("Test","Type","");XmlElementelementTypeCode=xmlDocument.CreateElement("Type","TCode","");XmlTextxmlTextTypeCode=xmlDocument.CreateTextNode(tt.TtCode);elementTypeCode.AppendChild(xmlTextTypeCode);elementType.AppendChild(elementTypeCode);XmlElementelementTypeName=xmlDocument.CreateElement("Type","TName","");XmlTextxmlTextTypeName=xmlDocument.CreateTextNode(tt.TtName);elementTypeName.AppendChild(xmlTextTypeName);elementType.AppendChild(elementTypeName);element.AppendChild(elementType);//testTypeendxmlElement.AppendChild(element);//ForxmlElementaddchildelement}xmlDocument.AppendChild(xmlElement);//ForxmlDocumentaddchildnodexmlDocument.Save(dataFile);//savethexmlDocument
附件:http://down.51cto.com/data/2358789声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。