1 XML file contents
<?xml version="1.0" encoding="utf-8" ? ><cultures > <daojia> <book> <name> ethics by </name> <author> Lao zi </author> </book> <book> <name> The beginning of the Canon </name> <author> Guan Yin </author> </book> </daojia> <fojia> <book> <name> Diamond Sutra </name > <author> sakyamuni Buddha </author> </book> <book> <name> Tibetan Bodhisattva's Sutra < /name> <author> Buddha Bodhisattva </author> </book> </fojia> </cultures >
2 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) - { - //1.xml file must be in the correct format theXDocument file = Xdocument.load ("1.xml"); - //gets the root node of the XML file -XElement xle =file. Root; - + -Ienumerable<xelement> ixt=xle. Elements (); + A foreach(varIteminchixt) at { - Console.WriteLine (item. Name); - } - - Console.readkey (); - } in } -}
3 effects
Name of the direct (first-level) child node under the C # XML output XML root node