1 Code
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingSystem.Xml.Linq;7 8 namespaceConsoleApplication89 {Ten class Program One { A Static voidMain (string[] args) - { -XDocument xmlfile =NewXDocument (); the - //setting the root element -XElement root =NewXElement ("Cultures"); - + //Establish a node with attribute values; <daojia count= "comment=" good "> -XElement Daojia =NewXElement ("Daojia"); +Daojia. Setattributevalue ("Count"," -"); ADaojia. Setattributevalue ("Comment","Good"); at - /*************************************************************************************/ - - //to make such an effect - //<book> - //<name> ethics through </name> in //<author> Lao Zi </author> - //</book> toXElement Book1 =NewXElement (" Book"); +Book1. Setelementvalue ("name","Moral Sutra"); -Book1. Setelementvalue ("author","Lao Tzu");//Lee Ear, is rumored to be Lao Zi, hey. the //No matter who he is, anyway, the moral of the book is super intelligent. * /*************************************************************************************/ $ Panax Notoginseng Daojia. ADD (BOOK1); - //The first-level child node of the Daojia programming cultures the Root. ADD (Daojia); + A //The root node can only be one the Xmlfile.add (root); + //Save File -Xmlfile.save ("Test.xml"); $ $ //read the XML file written by the program and print it to the console - varReadxml= Xdocument.load ("Test.xml"); - Console.WriteLine (readxml.root); the - Console.readkey ();Wuyi } the } -}
2 effects
3 text that is not printed
C # XML adds child elements with content to an element to add child elements with content to an element