Example Analysis of XDocument and XmlDocument in XML
This article mainly shows you the "sample analysis of XDocument and XmlDocument in XML", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let the editor lead you to study and study the "sample analysis of XDocument and XmlDocument in XML".
XmlDocument StringBuilder str = new StringBuilder (); XmlDocument document = new XmlDocument (); document.Load ("List1.xml"); XmlNodeList nodelist = document.GetElementsByTagName ("person"); foreach (XmlNode item in nodelist) {str.Append (item.FirstChild.InnerText.ToString ()) Str.Append ("");} textBox1.Text = str.ToString ()
You can get the specified name or ID through document, which is the specified name. Then output the contents of the first child node under the name node by traversing.
XDocument XDocument document = XDocument.Load ("List1.xml"); XElement rootElement = document.Root; IEnumerable ie = rootElement.Descendants ("person") .Where (x = > Convert.ToInt32 (x.Attribute ("id"). Value) > 1); foreach (var item in ie) {textBox1.Text + = item.Attribute ("id"). Value+ "\ t";}
Through XDocument, we can query the data we need more conveniently and quickly, which can be retrieved with lambda expressions.
The above is all the content of the article "sample Analysis of XDocument and XmlDocument in XML". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!