In. net can also be written to XML through XmlDocument and XDocument. XmlDocument is a standard XML writing class that was originally supported. now the extended XDocument class is more convenient to use, the following uses the XDocument class to write an XML file.
In. net can also be written to XML through XmlDocument and XDocument. XmlDocument is a standard XML writing class that was originally supported. now the extended XDocument class is more convenient to use, the following uses the XDocument class to write an XML file.
Write steps:
(1) first create an XDocument object
(2) set XML document definitions
(3) Create a root node
(4) Create subnodes in the cyclic list set (here the person class is used to input data)
(5) save to file
List
List = new List
(); List. add (new person () {name = "IstarI", age = 20, Email = "1061399756@qq.com"}); list. add (new person () {name = "Orange", age = 20, Email = "521@qq.com "}); // 1. create an XDocument object XDocument xDoc = new XDocument (); XDeclaration XDec = new XDeclaration ("1.0", "UTF-8", "no "); // Set the xml document definition xDoc. declaration = XDec; // 2. create the root node XElement rootElement = new XElement ("List"); xDoc. add (rootElement); // 3. create a subnode for (int I = 0; I
After writing, the file will appear in Debug, and then open it to view the desired result.
The above is the XML (2) content written to XML through XmlDocument and XDocument. For more information, see PHP Chinese website (www.php1.cn )!