LINQ
XML处理
1.How to create xml ?
XDocument customer = new XDocument( new XDeclaration("1.0", "UTF-16", "yes"), new XElement("customer", new XAttribute("id", "C01"), new XElement("firstName", "Paolo"), new XElement("lastName", "Pialorsi"), new XElement("addresses", new XElement("address", new XAttribute("type", "email"), "paolo@devleap.it"), new XElement("address", new XAttribute("type", "url"), "http://www.devleap.it/"), new XElement("address", new XAttribute("type", "home"), "Brescia - Italy"))));
LINQ create xml document is very easy,and clearly.
2.How to create xml in loop
//1.Declare Xdocument and have to set root node XDocument Content = new XDocument( new XElement("json") ); //2.Add element to document XAttribute ID = new XAttribute("id", 1); XElement XmlElement = new XElement("School", ID, "南十三大学"); Content.Root.Add(XmlElement);
3.How to remove all nodes attributes?
Content.Descendants().Attributes().Remove();
4.XmlReader how to read xml document content?
XmlReader reader = Content.Root.CreateReader(); reader.MoveToContent(); string result = reader.ReadInnerXml();