学习xml笔记,核心代码片段,测试结果在附件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