![]() ![]() Notice that the same query returned the one Root node instead of the three child nodes. This example produces the following output: Querying tree loaded with XDocument.Load XDocument doc = XDocument.Load("Test.xml") Ĭonsole.WriteLine("Querying tree loaded with XDocument.Load")ĭim doc As XDocument = XDocument.Load("Test.xml") Create a simple document and write it to a fileįile.WriteAllText("Test.xml", tree loaded with XDocument.Load") The next example does the same as the one above, but the XML tree has been loaded into an XDocument, rather than an XElement. This example produces the following output: Querying tree loaded with XElement.LoadĮxample: Load an XML tree using XDocument.Load, then query for child elements ' Create a simple document and write it to a fileįile.WriteAllText("Test.xml", "" + Environment.NewLine + _Ĭonsole.WriteLine("Querying tree loaded with XElement.Load")ĭim doc As XElement = XElement.Load("Test.xml")ĭim childList As IEnumerable(Of XElement) = _ XElement doc = XElement.Load("Test.xml") Create a simple document and write it to a fileįile.WriteAllText("Test.xml", tree loaded with XElement.Load") It then queries for the child elements of the root of the tree. ![]() This first example loads an XML tree using Load. Example: Load an XML tree using XElement.Load, then query for child elements The LINQ to XML axes operate relative to the root node. However, when you load the same XML document into an XDocument via XDocument.Load, the root of the tree is an XDocument node, and the root element of the loaded document is the one allowed child XElement node of the XDocument. When you load an XML document into an XElement via XElement.Load, the XElement at the root of the XML tree contains the root element of the loaded document. Comparison of XDocument.Load and XElement.Load The query you write when you load a document via XDocument.Load differs slightly from what you write when you load via XElement.Load. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |