From 3465c203e128f63d2074219aff6cb045d87a0f01 Mon Sep 17 00:00:00 2001 From: jameshkramer Date: Tue, 18 Feb 2020 14:21:11 -0800 Subject: [PATCH 1/6] 10). Add topic files 15 to 18 --- .openpublishing.redirection.json | 40 ++++ .../functional-construction-linq-to-xml.md | 66 ------ .../linq/how-to-catch-parsing-errors.md | 38 ---- .../how-to-create-a-tree-from-an-xmlreader.md | 50 ----- .../linq/how-to-load-xml-from-a-file.md | 44 ---- ...ite-space-while-loading-or-parsing-xml1.md | 33 --- docs/standard/linq/catch-parsing-errors.md | 61 ++++++ docs/standard/linq/create-tree-xmlreader.md | 65 ++++++ docs/standard/linq/functional-construction.md | 99 +++++++++ docs/standard/linq/linq-xml-vs-dom.md | 2 +- .../linq/load-xml-file.md} | 29 +-- ...reserve-white-space-loading-parsing-xml.md | 32 +++ docs/standard/linq/toc.yml | 4 +- docs/standard/linq/xml-literals.md | 204 ++++++++++++++++++ .../functional-construction-linq-to-xml.md | 55 ----- .../linq/how-to-catch-parsing-errors.md | 40 ---- .../how-to-create-a-tree-from-an-xmlreader.md | 53 ----- .../linq/introduction-to-xml-literals.md | 194 ----------------- ...hite-space-while-loading-or-parsing-xml.md | 36 ---- 19 files changed, 521 insertions(+), 624 deletions(-) delete mode 100644 docs/csharp/programming-guide/concepts/linq/functional-construction-linq-to-xml.md delete mode 100644 docs/csharp/programming-guide/concepts/linq/how-to-catch-parsing-errors.md delete mode 100644 docs/csharp/programming-guide/concepts/linq/how-to-create-a-tree-from-an-xmlreader.md delete mode 100644 docs/csharp/programming-guide/concepts/linq/how-to-load-xml-from-a-file.md delete mode 100644 docs/csharp/programming-guide/concepts/linq/preserving-white-space-while-loading-or-parsing-xml1.md create mode 100644 docs/standard/linq/catch-parsing-errors.md create mode 100644 docs/standard/linq/create-tree-xmlreader.md create mode 100644 docs/standard/linq/functional-construction.md rename docs/{visual-basic/programming-guide/concepts/linq/how-to-load-xml-from-a-file.md => standard/linq/load-xml-file.md} (57%) create mode 100644 docs/standard/linq/preserve-white-space-loading-parsing-xml.md create mode 100644 docs/standard/linq/xml-literals.md delete mode 100644 docs/visual-basic/programming-guide/concepts/linq/functional-construction-linq-to-xml.md delete mode 100644 docs/visual-basic/programming-guide/concepts/linq/how-to-catch-parsing-errors.md delete mode 100644 docs/visual-basic/programming-guide/concepts/linq/how-to-create-a-tree-from-an-xmlreader.md delete mode 100644 docs/visual-basic/programming-guide/concepts/linq/introduction-to-xml-literals.md delete mode 100644 docs/visual-basic/programming-guide/concepts/linq/preserving-white-space-while-loading-or-parsing-xml.md diff --git a/.openpublishing.redirection.json b/.openpublishing.redirection.json index 8698c4dc83077..a7fa6d3b9830c 100644 --- a/.openpublishing.redirection.json +++ b/.openpublishing.redirection.json @@ -1257,6 +1257,26 @@ "redirect_url": "/dotnet/standard/linq/build-linq-xml-examples", "redirect_document_id": true }, + { + "source_path": "docs/csharp/programming-guide/concepts/linq/how-to-catch-parsing-errors.md", + "redirect_url": "/dotnet/standard/linq/catch-parsing-errors", + "redirect_document_id": true + }, + { + "source_path": "docs/csharp/programming-guide/concepts/linq/how-to-create-a-tree-from-an-xmlreader.md", + "redirect_url": "/dotnet/standard/linq/create-tree-xmlreader", + "redirect_document_id": true + }, + { + "source_path": "docs/csharp/programming-guide/concepts/linq/how-to-load-xml-from-a-file.md", + "redirect_url": "/dotnet/standard/linq/load-xml-file", + "redirect_document_id": true + }, + { + "source_path": "docs/csharp/programming-guide/concepts/linq/preserving-white-space-while-loading-or-parsing-xml1.md", + "redirect_url": "/dotnet/standard/linq/preserve-white-space-loading-parsing-xml", + "redirect_document_id": true + }, { "source_path": "docs/csharp/programming-guide/concepts/threading/how-to-use-a-thread-pool.md", "redirect_url": "/dotnet/api/system.threading.threadpool.queueuserworkitem" @@ -4252,6 +4272,26 @@ "source_path": "docs/visual-basic/programming-guide/concepts/linq/how-to-build-linq-to-xml-examples.md", "redirect_url": "/dotnet/standard/linq/build-linq-xml-examples" }, + { + "source_path": "docs/visual-basic/programming-guide/concepts/linq/how-to-catch-parsing-errors.md", + "redirect_url": "/dotnet/standard/linq/catch-parsing-errors", + "redirect_document_id": false + }, + { + "source_path": "docs/visual-basic/programming-guide/concepts/linq/how-to-create-a-tree-from-an-xmlreader.md", + "redirect_url": "/dotnet/standard/linq/create-tree-xmlreader", + "redirect_document_id": false + }, + { + "source_path": "docs/visual-basic/programming-guide/concepts/linq/how-to-load-xml-from-a-file.md", + "redirect_url": "/dotnet/standard/linq/load-xml-file", + "redirect_document_id": false + }, + { + "source_path": "docs/visual-basic/programming-guide/concepts/linq/preserving-white-space-while-loading-or-parsing-xml.md", + "redirect_url": "/dotnet/standard/linq/preserve-white-space-loading-parsing-xml", + "redirect_document_id": false + }, { "source_path": "docs/visual-basic/programming-guide/concepts/threading/how-to-use-a-thread-pool.md", "redirect_url": "/dotnet/api/system.threading.threadpool.queueuserworkitem" diff --git a/docs/csharp/programming-guide/concepts/linq/functional-construction-linq-to-xml.md b/docs/csharp/programming-guide/concepts/linq/functional-construction-linq-to-xml.md deleted file mode 100644 index 27ace03d9c377..0000000000000 --- a/docs/csharp/programming-guide/concepts/linq/functional-construction-linq-to-xml.md +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: "Functional Construction (LINQ to XML) (C#)" -ms.date: 07/20/2015 -ms.assetid: 57a82bcf-de03-4f1c-a0c8-9a76e989d542 ---- -# Functional Construction (LINQ to XML) (C#) -[!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)] provides a powerful way to create XML elements called *functional construction*. Functional construction is the ability to create an XML tree in a single statement. - - There are several key features of the [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)] programming interface that enable functional construction: - -- The constructor takes various types of arguments for content. For example, you can pass another object, which becomes a child element. You can pass an object, which becomes an attribute of the element. Or you can pass any other type of object, which is converted to a string and becomes the text content of the element. - -- The constructor takes a `params` array of type , so that you can pass any number of objects to the constructor. This enables you to create an element that has complex content. - -- If an object implements , the collection in the object is enumerated, and all items in the collection are added. If the collection contains or objects, each item in the collection is added separately. This is important because it lets you pass the results of a LINQ query to the constructor. - - These features enable you to write code to create an XML tree. The following is an example: - -```csharp -XElement contacts = - new XElement("Contacts", - new XElement("Contact", - new XElement("Name", "Patrick Hines"), - new XElement("Phone", "206-555-0144"), - new XElement("Address", - new XElement("Street1", "123 Main St"), - new XElement("City", "Mercer Island"), - new XElement("State", "WA"), - new XElement("Postal", "68042") - ) - ) - ); -``` - - These features also enable you to write code that uses the results of LINQ queries when you create an XML tree, as follows: - -```csharp -XElement srcTree = new XElement("Root", - new XElement("Element", 1), - new XElement("Element", 2), - new XElement("Element", 3), - new XElement("Element", 4), - new XElement("Element", 5) -); -XElement xmlTree = new XElement("Root", - new XElement("Child", 1), - new XElement("Child", 2), - from el in srcTree.Elements() - where (int)el > 2 - select el -); -Console.WriteLine(xmlTree); -``` - - This example produces the following output: - -```xml - - 1 - 2 - 3 - 4 - 5 - -``` - \ No newline at end of file diff --git a/docs/csharp/programming-guide/concepts/linq/how-to-catch-parsing-errors.md b/docs/csharp/programming-guide/concepts/linq/how-to-catch-parsing-errors.md deleted file mode 100644 index 363f5be0cd6e0..0000000000000 --- a/docs/csharp/programming-guide/concepts/linq/how-to-catch-parsing-errors.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -title: "How to catch parsing errors (C#)" -ms.date: 07/20/2015 -ms.assetid: bfb612d4-5605-48ef-8c93-915cf9d5dcfb ---- -# How to catch parsing errors (C#) -This topic shows how to detect badly formed or invalid XML. - - [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)] is implemented using . If badly formed or invalid XML is passed to [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)], the underlying class will throw an exception. The various methods that parse XML, such as , do not catch the exception; the exception can then be caught by your application. - -## Example - The following code tries to parse invalid XML: - -```csharp -try { - XElement contacts = XElement.Parse( - @" - - Jim Wilson - - "); - - Console.WriteLine(contacts); -} -catch (System.Xml.XmlException e) -{ - Console.WriteLine(e.Message); -} -``` - - When you run this code, it throws the following exception: - -```console -The 'Contacts' start tag on line 1 does not match the end tag of 'Contcts'. Line 5, position 13. -``` - - For information about the exceptions that you can expect the , , , and methods to throw, see the documentation. - \ No newline at end of file diff --git a/docs/csharp/programming-guide/concepts/linq/how-to-create-a-tree-from-an-xmlreader.md b/docs/csharp/programming-guide/concepts/linq/how-to-create-a-tree-from-an-xmlreader.md deleted file mode 100644 index 1df3244b7402b..0000000000000 --- a/docs/csharp/programming-guide/concepts/linq/how-to-create-a-tree-from-an-xmlreader.md +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: "How to create a tree from an XmlReader (C#)" -ms.date: 07/20/2015 -ms.assetid: 60951c9c-7087-406c-b5bb-c60e58609b21 ---- -# How to create a tree from an XmlReader (C#) -This topic shows how to create an XML tree directly from an . To create an from an , you must position the on an element node. The will skip comments and processing instructions, but if the is positioned on a text node, an error will be thrown. To avoid such errors, always position the on an element before you create an XML tree from the . - -## Example - This example uses the following XML document: [Sample XML File: Books (LINQ to XML)](./sample-xml-file-books-linq-to-xml.md). - - The following code creates an `T:System.Xml.XmlReader` object, and then reads nodes until it finds the first element node. It then loads the object. - -```csharp -XmlReader r = XmlReader.Create("books.xml"); -while (r.NodeType != XmlNodeType.Element) - r.Read(); -XElement e = XElement.Load(r); -Console.WriteLine(e); -``` - - This example produces the following output: - -```xml - - - Garghentini, Davide - XML Developer's Guide - Computer - 44.95 - 2000-10-01 - An in-depth look at creating applications - with XML. - - - Garcia, Debra - Midnight Rain - Fantasy - 5.95 - 2000-12-16 - A former architect battles corporate zombies, - an evil sorceress, and her own childhood to become queen - of the world. - - -``` - -## See also - -- [Parsing XML (C#)](how-to-parse-a-string.md) diff --git a/docs/csharp/programming-guide/concepts/linq/how-to-load-xml-from-a-file.md b/docs/csharp/programming-guide/concepts/linq/how-to-load-xml-from-a-file.md deleted file mode 100644 index d4641e6d992e6..0000000000000 --- a/docs/csharp/programming-guide/concepts/linq/how-to-load-xml-from-a-file.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: "How to load XML from a file (C#)" -ms.date: 07/20/2015 -ms.assetid: 3ed38487-8028-4209-9872-c8dce0ed4dfe ---- -# How to load XML from a file (C#) -This topic shows how to load XML from a URI by using the method. - -## Example - The following example shows how to load an XML document from a file. The following example loads books.xml and outputs the XML tree to the console. - - This example uses the following XML document: [Sample XML File: Books (LINQ to XML)](./sample-xml-file-books-linq-to-xml.md). - -```csharp -XElement booksFromFile = XElement.Load(@"books.xml"); -Console.WriteLine(booksFromFile); -``` - - This code produces the following output: - -```xml - - - Garghentini, Davide - XML Developer's Guide - Computer - 44.95 - 2000-10-01 - An in-depth look at creating applications - with XML. - - - Garcia, Debra - Midnight Rain - Fantasy - 5.95 - 2000-12-16 - A former architect battles corporate zombies, - an evil sorceress, and her own childhood to become queen - of the world. - - -``` - \ No newline at end of file diff --git a/docs/csharp/programming-guide/concepts/linq/preserving-white-space-while-loading-or-parsing-xml1.md b/docs/csharp/programming-guide/concepts/linq/preserving-white-space-while-loading-or-parsing-xml1.md deleted file mode 100644 index 27838a95b4907..0000000000000 --- a/docs/csharp/programming-guide/concepts/linq/preserving-white-space-while-loading-or-parsing-xml1.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: "Preserving White Space while Loading or Parsing XML" -ms.date: 07/20/2015 -ms.assetid: f3ff58c4-55aa-4fcd-b933-e3a2ee6e706c ---- -# Preserving White Space while Loading or Parsing XML -This topic describes how to control the white-space behavior of [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)]. - - A common scenario is to read indented XML, create an in-memory XML tree without any white space text nodes (that is, not preserving white space), perform some operations on the XML, and then save the XML with indentation. When you serialize the XML with formatting, only significant white space in the XML tree is preserved. This is the default behavior for [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)]. - - Another common scenario is to read and modify XML that has already been intentionally indented. You might not want to change this indentation in any way. To do this in [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)], you preserve white space when you load or parse the XML and disable formatting when you serialize the XML. - - This topic describes the white-space behavior of methods that populate XML trees. For information about controlling white space when you serialize XML trees, see [Preserving White Space While Serializing](./preserving-white-space-while-serializing.md). - -## Behavior of Methods that Populate XML Trees - The following methods in the and classes populate an XML tree. You can populate an XML tree from a file, a , an , or a string: - -- - -- - -- - -- - - If the method does not take as an argument, the method will not preserve insignificant white space. - - In most cases, if the method takes as an argument, you can optionally preserve insignificant white space as text nodes in the XML tree. However, if the method is loading the XML from an , then the determines whether white space will be preserved or not. Setting will have no effect. - - With these methods, if white space is preserved, insignificant white space is inserted into the XML tree as nodes. If white space is not preserved, text nodes are not inserted. - - You can create an XML tree by using an . Nodes that are written to the are populated in the tree. However, when you build an XML tree using this method, all nodes are preserved, regardless of whether the node is white space or not, or whether the white space is significant or not. - \ No newline at end of file diff --git a/docs/standard/linq/catch-parsing-errors.md b/docs/standard/linq/catch-parsing-errors.md new file mode 100644 index 0000000000000..fcf0f933e974d --- /dev/null +++ b/docs/standard/linq/catch-parsing-errors.md @@ -0,0 +1,61 @@ +--- +title: "How to catch parsing errors - LINQ to XML" +ms.date: 7/20/2015 +dev_langs: + - "csharp" + - "vb" +ms.assetid: bfb612d4-5605-48ef-8c93-915cf9d5dcfb +--- + +# How to catch parsing errors (LINQ to XML) + +This article shows how to detect badly formed or invalid XML. + +LINQ to XML is implemented using . If badly formed or invalid XML is passed to LINQ to XML, the underlying class will throw an exception. The various methods that parse XML, such as , do not catch the exception; the exception can then be caught by your application. + +## Example: Parse invalid XML + +The following code tries to parse invalid XML. + +```csharp +try { + XElement contacts = XElement.Parse( + @" + + Jim Wilson + + "); + + Console.WriteLine(contacts); +} +catch (System.Xml.XmlException e) +{ + Console.WriteLine(e.Message); +} +``` + +```vb +Try + Dim contacts As XElement = XElement.Parse("" & vbCrLf & _ + " " & vbCrLf & _ + " Jim Wilson" & vbCrLf & _ + " " & vbCrLf & _ + "") + + Console.WriteLine(contacts) +Catch e As System.Xml.XmlException + Console.WriteLine(e.Message) +End Try +``` + +Because of the invalid end tag ``, the example throws the following exception: + +```console +The 'Contacts' start tag on line 1 doesn't match the end tag of 'Contcts'. Line 5, position 13. +``` + +For information about the exceptions that the , , , and methods throw, see the documentation. + +## See also + +- [How to parse a string (LINQ to XML)](parse-string.md) diff --git a/docs/standard/linq/create-tree-xmlreader.md b/docs/standard/linq/create-tree-xmlreader.md new file mode 100644 index 0000000000000..79c81ed00e1a2 --- /dev/null +++ b/docs/standard/linq/create-tree-xmlreader.md @@ -0,0 +1,65 @@ +--- +title: "How to create a tree from an XmlReader - LINQ to XML" +ms.date: 07/20/2015 +dev_langs: + - "csharp" + - "vb" +ms.assetid: 60951c9c-7087-406c-b5bb-c60e58609b21 +--- + +# How to create a tree from an XmlReader (LINQ to XML) + +This article shows how to create an XML tree directly from an . To create an from an , you position the on an element node. The will skip comments and processing instructions, but if the is positioned on a text node, an error will be thrown. To avoid such errors, position the on an element before you create an XML tree from the . + +## Example: Load XElement object from an XmlReader object + +This example uses the XML document [Sample XML file: Books (LINQ to XML)](sample-xml-file-books.md). + +The following code creates a `T:System.Xml.XmlReader` object, reads nodes until it finds the first element node, and loads the object. + +```csharp +XmlReader r = XmlReader.Create("books.xml"); +while (r.NodeType != XmlNodeType.Element) + r.Read(); +XElement e = XElement.Load(r); +Console.WriteLine(e); +``` + +```vb +Dim r As XmlReader = XmlReader.Create("books.xml") +Do While r.NodeType <> XmlNodeType.Element + r.Read() +Loop +Dim e As XElement = XElement.Load(r) +Console.WriteLine(e) +``` + +The example produces this output: + +```xml + + + Garghentini, Davide + XML Developer's Guide + Computer + 44.95 + 2000-10-01 + An in-depth look at creating applications + with XML. + + + Garcia, Debra + Midnight Rain + Fantasy + 5.95 + 2000-12-16 + A former architect battles corporate zombies, + an evil sorceress, and her own childhood to become queen + of the world. + + +``` + +## See also + +- [Parse XML](parse-string.md) diff --git a/docs/standard/linq/functional-construction.md b/docs/standard/linq/functional-construction.md new file mode 100644 index 0000000000000..b981846c654d4 --- /dev/null +++ b/docs/standard/linq/functional-construction.md @@ -0,0 +1,99 @@ +--- +title: "Functional construction - LINQ to XML" +ms.date: 07/20/2015 +dev_langs: + - "csharp" + - "vb" +ms.assetid: 57a82bcf-de03-4f1c-a0c8-9a76e989d542 +--- + +# Functional construction (LINQ to XML) + +LINQ to XML provides a powerful way to create XML elements called *functional construction*. Functional construction enables you to create an XML tree in a single statement. + +Several key features of the LINQ to XML programming interface are used in functional construction: + +- The constructor takes various types of arguments for content. For example, you can pass another object, which becomes a child element. You can pass an object, which becomes an attribute of the element. Or you can pass any other type of object, which is converted to a string and becomes the text content of the element. +- The constructor takes a `params` array of type , so that you can pass any number of objects to the constructor. This enables you to create an element that has complex content. +- If an object implements , the collection in the object is enumerated, and all items in the collection are added. If the collection contains or objects, each item in the collection is added separately. This is important because it lets you pass the results of a LINQ query to the constructor. + +## Example: Create an XML tree + +You can use functional construction to write code to create an XML tree. The following is an example: + +```csharp +XElement contacts = + new XElement("Contacts", + new XElement("Contact", + new XElement("Name", "Patrick Hines"), + new XElement("Phone", "206-555-0144"), + new XElement("Address", + new XElement("Street1", "123 Main St"), + new XElement("City", "Mercer Island"), + new XElement("State", "WA"), + new XElement("Postal", "68042") + ) + ) + ); +``` + +## Example: Create an XML tree using LINQ query results + +These features also enable you to write code that uses the results of LINQ queries when you create an XML tree, as in the following example: + +```csharp +XElement srcTree = new XElement("Root", + new XElement("Element", 1), + new XElement("Element", 2), + new XElement("Element", 3), + new XElement("Element", 4), + new XElement("Element", 5) +); +XElement xmlTree = new XElement("Root", + new XElement("Child", 1), + new XElement("Child", 2), + from el in srcTree.Elements() + where (int)el > 2 + select el +); +Console.WriteLine(xmlTree); +``` + +In Visual Basic, the same thing is accomplished with XML literals: + +```vb +Dim srcTree As XElement = _ + + 1 + 2 + 3 + 4 + 5 + +Dim xmlTree As XElement = _ + + 1 + 2 + <%= From el In srcTree.Elements() _ + Where CInt(el) > 2 _ + Select el %> + +Console.WriteLine(xmlTree) +``` + +The example produces this output: + +```xml + + 1 + 2 + 3 + 4 + 5 + +``` + +## See also + +- [Create XML Trees in C# (LINQ to XML)](create-xml-trees.md) +- [XML literals in Visual Basic (LINQ to XML)](xml-literals.md) diff --git a/docs/standard/linq/linq-xml-vs-dom.md b/docs/standard/linq/linq-xml-vs-dom.md index fa73441d52f31..4b8a66ef03859 100644 --- a/docs/standard/linq/linq-xml-vs-dom.md +++ b/docs/standard/linq/linq-xml-vs-dom.md @@ -162,7 +162,7 @@ Another problem with the DOM is that it doesn't let you change the name of a nod ## Static method support for loading XML -LINQ to XML lets you load XML by using static methods, instead of instance methods. This simplifies loading and parsing. For more information, see [How to load XML from a file](load-xml-file.md). +LINQ to XML lets you load XML by using static methods, instead of instance methods. This simplifies loading and parsing. For more information, see [How to load XML from a file (LINQ to XML)](load-xml-file.md). ## Removal of support for DTD constructs diff --git a/docs/visual-basic/programming-guide/concepts/linq/how-to-load-xml-from-a-file.md b/docs/standard/linq/load-xml-file.md similarity index 57% rename from docs/visual-basic/programming-guide/concepts/linq/how-to-load-xml-from-a-file.md rename to docs/standard/linq/load-xml-file.md index 7b39d8519a757..a6a0e2890bc23 100644 --- a/docs/visual-basic/programming-guide/concepts/linq/how-to-load-xml-from-a-file.md +++ b/docs/standard/linq/load-xml-file.md @@ -1,24 +1,33 @@ --- -title: "How to: Load XML from a File" +title: "How to load XML from a file - LINQ to XML" ms.date: 07/20/2015 -ms.assetid: e2d337ad-8ac8-4671-b694-30e5ca1413b7 +dev_langs: + - "csharp" + - "vb" +ms.assetid: 3ed38487-8028-4209-9872-c8dce0ed4dfe --- -# How to: Load XML from a File (Visual Basic) -This topic shows how to load XML from a URI by using the method. +# How to load XML from a file (LINQ to XML) -## Example +This article shows how to load XML from a file using the method. -The following example shows how to load an XML document from a file. The following example loads books.xml and outputs the XML tree to the console. +## Example: Load XML document from a file -This example uses the following XML document: [Sample XML File: Books (LINQ to XML)](../../../../visual-basic/programming-guide/concepts/linq/sample-xml-file-books-linq-to-xml.md). +The following example shows how to load an XML document from a file by providing with the URI that references the file. The example loads books.xml and outputs the XML tree to the console. + +The contents of books.xml are shown in [Sample XML file: Books (LINQ to XML)](sample-xml-file-books.md). + +```csharp +XElement booksFromFile = XElement.Load(@"books.xml"); +Console.WriteLine(booksFromFile); +``` ```vb Dim booksFromFile As XElement = XElement.Load("books.xml") Console.WriteLine(booksFromFile) ``` -This code produces the following output: +The example produces this output: ```xml @@ -43,7 +52,3 @@ This code produces the following output: ``` - -## See also - -- [Parsing XML (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/parsing-xml.md) diff --git a/docs/standard/linq/preserve-white-space-loading-parsing-xml.md b/docs/standard/linq/preserve-white-space-loading-parsing-xml.md new file mode 100644 index 0000000000000..8491a9ed2ef37 --- /dev/null +++ b/docs/standard/linq/preserve-white-space-loading-parsing-xml.md @@ -0,0 +1,32 @@ +--- +title: "Preserve white space while loading or parsing XML - LINQ to XML" +ms.date: 07/20/2015 +ms.assetid: f3ff58c4-55aa-4fcd-b933-e3a2ee6e706c +--- + +# Preserve white space while loading or parsing XML (LINQ to XML) + +This article describes how to control the white-space behavior of LINQ to XML. + +A common scenario is to read indented XML, create an in-memory XML tree without any white space text nodes (that is, not preserving white space), do some operations on the XML, and then save the XML with indentation. When you serialize the XML with formatting, only significant white space in the XML tree is preserved. This is the default behavior for LINQ to XML. + +Another common scenario is to read and modify XML that has already been intentionally indented. You might not want to change this indentation in any way. To do this in LINQ to XML, you preserve white space when you load or parse the XML and disable formatting when you serialize the XML. + +This article describes the white-space behavior of methods that populate XML trees. For information about controlling white space when you serialize XML trees, see [Preserve white space while serializing (LINQ to XML)](preserve-white-space-serializing.md). + +## Behavior of methods that populate XML trees + +The following methods in the and classes populate an XML tree. You can populate an XML tree from a file, a , an , or a string: + +- +- +- +- + +If the method doesn't take as an argument, the method won't preserve insignificant white space. + +In most cases, if the method takes as an argument, you can optionally preserve insignificant white space as text nodes in the XML tree. However, if the method is loading the XML from an , then the determines whether white space will be preserved or not. Setting will have no effect. + +With these methods, if white space is preserved, insignificant white space is inserted into the XML tree as nodes. If white space isn't preserved, text nodes aren't inserted. + +You can create an XML tree by using an . Nodes that are written to the are populated in the tree. However, when you build an XML tree using this method, all nodes are preserved, regardless of whether the node is white space or not, or whether the white space is significant or not. diff --git a/docs/standard/linq/toc.yml b/docs/standard/linq/toc.yml index 5f68ee042eba3..4c1e351436ca7 100644 --- a/docs/standard/linq/toc.yml +++ b/docs/standard/linq/toc.yml @@ -304,8 +304,8 @@ href: mixed-declarative-code-imperative-code-bugs.md - name: "How to stream XML fragments with access to header information" href: stream-xml-fragments-access-header-information.md - - name: "How to do streaming transform of large XML documents" - href: do-streaming-transform-large-xml-documents.md + - name: "How to perform streaming transform of large XML documents" + href: perform-streaming-transform-large-xml-documents.md - name: "How to read and write an encoded document" href: read-write-encoded-document.md - name: Use XSLT to transform an XML tree diff --git a/docs/standard/linq/xml-literals.md b/docs/standard/linq/xml-literals.md new file mode 100644 index 0000000000000..068b6d86268e8 --- /dev/null +++ b/docs/standard/linq/xml-literals.md @@ -0,0 +1,204 @@ +--- +title: XML Literals in Visual Basic - LINQ to XML +ms.date: 07/20/2015 +ms.assetid: cc74234a-0bac-4327-9c8c-5a2ead15b595 +--- + +# XML Literals in Visual Basic (LINQ to XML) + +This article provides information about creating XML trees in Visual Basic using XML literals and embedded expressions. + +## Example: Use XML literals to create an XML tree + +The following example shows how to create an , in this case `contacts`, with XML literals: + +```vb +Dim contacts As XElement = _ + + + Patrick Hines + 206-555-0144 +
+ 123 Main St + Mercer Island + WA + 68042 +
+
+
+``` + +## Example: Use XML literals to create an XElement with simple content + +You can create an that contains simple content, as follows: + +```vb +Dim n as XElement = Adventure Works +Console.WriteLine(n) +``` + +The example produces this output: + +```xml +Adventure Works +``` + +## Example: Use an XML literal to create an empty element + +You can create an empty , as follows: + +```vb +Dim n As XElement = +Console.WriteLine(n) +``` + +The example produces this output: + +```xml + +``` + +## Use embedded expressions to create content + +An important feature of XML literals is that they allow embedded expressions. Embedded expressions enable you to evaluate an expression and insert the results of the expression into the XML tree. If the expression evaluates to a type of , an element is inserted into the tree. If the expression evaluates to a type of , an attribute is inserted into the tree. You can insert elements and attributes into the tree only where they're valid. + +it's important to note that only a single expression can go into an embedded expression. You can't embed multiple statements. If an expression extends beyond a single line, you must use the line continuation character. + +If you use an embedded expression to add existing nodes (including elements) and attributes to a new XML tree and if the existing nodes are already parented, the nodes are cloned. The newly cloned nodes are attached to the new XML tree. If the existing nodes aren't parented, the nodes are simply attached to the new XML tree. The last example in this article demonstrates this. + +## Example: Use an embedded expression to insert an element + +The following example uses an embedded expression to insert an element into the tree: + +```vb +xmlTree1 As XElement = _ + + Contents + +Dim xmlTree2 As XElement = _ + + <%= xmlTree1. %> + +Console.WriteLine(xmlTree2) +``` + +The example produces this output: + +```xml + + Contents + +``` + +## Example: Use an embedded expression for content + +You can use an embedded expression to supply the content of an element: + +```vb +Dim str As String +str = "Some content" +Dim root As XElement = <%= str %> +Console.WriteLine(root) +``` + +The example produces this output: + +```xml +Some content +``` + +## Example: Use a LINQ query in an embedded expression + +You can use the results of a LINQ query to provide the content of an element: + +```vb +Dim arr As Integer() = {1, 2, 3} + +Dim n As XElement = _ + + <%= From i In arr Select <%= i %> %> + + +Console.WriteLine(n) +``` + +The example produces this output: + +```xml + + 1 + 2 + 3 + +``` + +## Example: Use an embedded expression to provide node names + +You can also use an embedded expression to calculate attribute names, attribute values, element names, and element values: + +```vb +Dim eleName As String = "ele" +Dim attName As String = "att" +Dim attValue As String = "aValue" +Dim eleValue As String = "eValue" +Dim n As XElement = _ + =<%= attValue %>> + <<%= eleName %>> + <%= eleValue %> + + +Console.WriteLine(n) +``` + +The example produces this output: + +```xml + + eValue + +``` + +## Example: Use an embedded expression to clone and attach nodes + +As mentioned earlier, if you use an embedded expression to add existing nodes (including elements) and attributes to a new XML tree, and if the nodes being added nodes are already parented, the nodes are cloned and the clones are attached to the new XML tree. If the existing nodes aren't parented, they are simply attached to the new XML tree. + +The following code demonstrates the behavior when you add a parented element to a tree, and when you add an element with no parent to a tree. + +```vb +' Create a tree with a child element. +Dim xmlTree1 As XElement = _ + + 1 + + +' Create an element that isn't parented. +Dim child2 As XElement = 2 + +' Create a tree and add Child1 and Child2 to it. +Dim xmlTree2 As XElement = _ + + <%= xmlTree1.(0) %> + <%= child2 %> + + +' Compare Child1 identity. +Console.WriteLine("Child1 was {0}", _ + IIf(xmlTree1.Element("Child1") Is xmlTree2.Element("Child1"), _ + "attached", "cloned")) + +' Compare Child2 identity. +Console.WriteLine("Child2 was {0}", _ + IIf(child2 Is xmlTree2.Element("Child2"), _ + "attached", "cloned")) +``` + +The example produces this output: + +```console +Child1 was cloned +Child2 was attached +``` + +## See also + +- [Functional construction (LINQ to XML)](functional-construction.md) diff --git a/docs/visual-basic/programming-guide/concepts/linq/functional-construction-linq-to-xml.md b/docs/visual-basic/programming-guide/concepts/linq/functional-construction-linq-to-xml.md deleted file mode 100644 index c2a77fa847c78..0000000000000 --- a/docs/visual-basic/programming-guide/concepts/linq/functional-construction-linq-to-xml.md +++ /dev/null @@ -1,55 +0,0 @@ ---- -title: "Functional Construction (LINQ to XML)" -ms.date: 07/20/2015 -ms.assetid: feac4273-39ab-43ae-bab7-4059c807a785 ---- -# Functional Construction (LINQ to XML) (Visual Basic) -[!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)] provides a powerful way to create XML elements called *functional construction*. Functional construction is the ability to create an XML tree in a single statement. - - There are several key features of the [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)] programming interface that enable functional construction: - -- The constructor takes various types of arguments for content. For example, you can pass another object, which becomes a child element. You can pass an object, which becomes an attribute of the element. Or you can pass any other type of object, which is converted to a string and becomes the text content of the element. - -- The constructor takes a `params` array of type , so that you can pass any number of objects to the constructor. This enables you to create an element that has complex content. - -- If an object implements , the collection in the object is enumerated, and all items in the collection are added. If the collection contains or objects, each item in the collection is added separately. This is important because it lets you pass the results of a LINQ query to the constructor. - - The following is an example: - - These features enable you to write code using XML literals to create an XML tree, and also to write code that uses the results of LINQ queries when you create an XML tree: - -```vb -Dim srcTree As XElement = _ - - 1 - 2 - 3 - 4 - 5 - -Dim xmlTree As XElement = _ - - 1 - 2 - <%= From el In srcTree.Elements() _ - Where CInt(el) > 2 _ - Select el %> - -Console.WriteLine(xmlTree) -``` - - This example produces the following output: - -```xml - - 1 - 2 - 3 - 4 - 5 - -``` - -## See also - -- [Creating XML Trees (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/creating-xml-trees.md) diff --git a/docs/visual-basic/programming-guide/concepts/linq/how-to-catch-parsing-errors.md b/docs/visual-basic/programming-guide/concepts/linq/how-to-catch-parsing-errors.md deleted file mode 100644 index 24a116af0a39f..0000000000000 --- a/docs/visual-basic/programming-guide/concepts/linq/how-to-catch-parsing-errors.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: "How to: Catch Parsing Errors" -ms.date: 07/20/2015 -ms.assetid: 22e9068e-ea58-447b-816e-cd1852c11787 ---- -# How to: Catch Parsing Errors (Visual Basic) -This topic shows how to detect badly formed or invalid XML. - - [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)] is implemented using . If badly formed or invalid XML is passed to [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)], the underlying class will throw an exception. The various methods that parse XML, such as , do not catch the exception; the exception can then be caught by your application. - - Note that you cannot get parse errors if you use XML literals. The Visual Basic compiler will catch errors of badly formed or invalid XML. - -## Example - The following code tries to parse invalid XML: - -```vb -Try - Dim contacts As XElement = XElement.Parse("" & vbCrLf & _ - " " & vbCrLf & _ - " Jim Wilson" & vbCrLf & _ - " " & vbCrLf & _ - "") - - Console.WriteLine(contacts) -Catch e As System.Xml.XmlException - Console.WriteLine(e.Message) -End Try -``` - - When you run this code, it throws the following exception: - -```console -The 'Contacts' start tag on line 1 does not match the end tag of 'Contcts'. Line 5, position 13. -``` - - For information about the exceptions that you can expect the , , , and methods to throw, see the documentation. - -## See also - -- [Parsing XML (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/parsing-xml.md) diff --git a/docs/visual-basic/programming-guide/concepts/linq/how-to-create-a-tree-from-an-xmlreader.md b/docs/visual-basic/programming-guide/concepts/linq/how-to-create-a-tree-from-an-xmlreader.md deleted file mode 100644 index 501d91e6f2e48..0000000000000 --- a/docs/visual-basic/programming-guide/concepts/linq/how-to-create-a-tree-from-an-xmlreader.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: "How to: Create a Tree from an XmlReader" -ms.date: 07/20/2015 -ms.assetid: 6de683d8-177d-402b-b0de-d0539f1ce5d8 ---- -# How to: Create a Tree from an XmlReader (Visual Basic) - -This topic shows how to create an XML tree directly from an . To create an from an , you must position the on an element node. The will skip comments and processing instructions, but if the is positioned on a text node, an error will be thrown. To avoid such errors, always position the on an element before you create an XML tree from the . - -## Example - -This example uses the following XML document: [Sample XML File: Books (LINQ to XML)](../../../../visual-basic/programming-guide/concepts/linq/sample-xml-file-books-linq-to-xml.md). - -The following code creates an `T:System.Xml.XmlReader` object, and then reads nodes until it finds the first element node. It then loads the object. - -```vb -Dim r As XmlReader = XmlReader.Create("books.xml") -Do While r.NodeType <> XmlNodeType.Element - r.Read() -Loop -Dim e As XElement = XElement.Load(r) -Console.WriteLine(e) -``` - -This example produces the following output: - -```xml - - - Garghentini, Davide - XML Developer's Guide - Computer - 44.95 - 2000-10-01 - An in-depth look at creating applications - with XML. - - - Garcia, Debra - Midnight Rain - Fantasy - 5.95 - 2000-12-16 - A former architect battles corporate zombies, - an evil sorceress, and her own childhood to become queen - of the world. - - -``` - -## See also - -- [Parsing XML (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/parsing-xml.md) diff --git a/docs/visual-basic/programming-guide/concepts/linq/introduction-to-xml-literals.md b/docs/visual-basic/programming-guide/concepts/linq/introduction-to-xml-literals.md deleted file mode 100644 index 923750d666148..0000000000000 --- a/docs/visual-basic/programming-guide/concepts/linq/introduction-to-xml-literals.md +++ /dev/null @@ -1,194 +0,0 @@ ---- -title: "Introduction to XML Literals in Visual Basic2" -ms.date: 07/20/2015 -ms.assetid: 94fc0e03-978e-4c08-ab6c-0dc3c1e64f10 ---- -# Introduction to XML Literals in Visual Basic -This section provides information about creating XML trees in Visual Basic. - - For information about using the results of LINQ queries as the content for an XML tree, see [Functional Construction (LINQ to XML) (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/functional-construction-linq-to-xml.md). - - For more information on XML literals in Visual Basic, see [Overview of LINQ to XML in Visual Basic](../../../../visual-basic/programming-guide/language-features/xml/overview-of-linq-to-xml.md). - -## Creating XML Trees - The following example shows how to create an , in this case `contacts`: - -```vb -Dim contacts As XElement = _ - - - Patrick Hines - 206-555-0144 -
- 123 Main St - Mercer Island - WA - 68042 -
-
-
-``` - -### Creating an XElement with Simple Content - You can create an that contains simple content, as follows: - -```vb -Dim n as XElement = Adventure Works -Console.WriteLine(n) -``` - - This example produces the following output: - -```xml -Adventure Works -``` - -### Creating an Empty Element - You can create an empty , as follows: - -```vb -Dim n As XElement = -Console.WriteLine(n) -``` - - This example produces the following output: - -```xml - -``` - -### Using Embedded Expressions - An important feature of XML literals is that they allow embedded expressions. Embedded expressions enable you to evaluate an expression and insert the results of the expression into the XML tree. If the expression evaluates to a type of , an element is inserted into the tree. If the expression evaluates to a type of , an attribute is inserted into the tree. You can insert elements and attributes into the tree only where they are valid. - - It is important to note that only a single expression can go into an embedded expression. You cannot embed multiple statements. If an expression extends beyond a single line, you must use the line continuation character. - - If you use an embedded expression to add existing nodes (including elements) and attributes to a new XML tree and if the existing nodes are already parented, the nodes are cloned. The newly cloned nodes are attached to the new XML tree. If the existing nodes are not parented, the nodes are simply attached to the new XML tree. The last example in this topic demonstrates this. - - The following example uses an embedded expression to insert an element into the tree: - -```vb -xmlTree1 As XElement = _ - - Contents - -Dim xmlTree2 As XElement = _ - - <%= xmlTree1. %> - -Console.WriteLine(xmlTree2) -``` - - This example produces the following output: - -```xml - - Contents - -``` - -### Using Embedded Expressions for Content - You can use an embedded expression to supply the content of an element: - -```vb -Dim str As String -str = "Some content" -Dim root As XElement = <%= str %> -Console.WriteLine(root) -``` - - This example produces the following output: - -```xml -Some content -``` - -### Using a LINQ Query in an Embedded Expression - You can use the results of a LINQ query for the content of an element: - -```vb -Dim arr As Integer() = {1, 2, 3} - -Dim n As XElement = _ - - <%= From i In arr Select <%= i %> %> - - -Console.WriteLine(n) -``` - - This example produces the following output: - -```xml - - 1 - 2 - 3 - -``` - -### Using Embedded Expressions for Node Names - You can also use embedded expressions to calculate attribute names, attribute values, element names, and element values: - -```vb -Dim eleName As String = "ele" -Dim attName As String = "att" -Dim attValue As String = "aValue" -Dim eleValue As String = "eValue" -Dim n As XElement = _ - =<%= attValue %>> - <<%= eleName %>> - <%= eleValue %> - - -Console.WriteLine(n) -``` - - This example produces the following output: - -```xml - - eValue - -``` - -### Cloning vs. Attaching - As mentioned earlier, if you use an embedded expression to add existing nodes (including elements) and attributes to a new XML tree, if the existing nodes are already parented, the nodes are cloned and the newly cloned nodes are attached to the new XML tree. If the existing nodes are not parented, they are simply attached to the new XML tree. - -```vb -' Create a tree with a child element. -Dim xmlTree1 As XElement = _ - - 1 - - -' Create an element that is not parented. -Dim child2 As XElement = 2 - -' Create a tree and add Child1 and Child2 to it. -Dim xmlTree2 As XElement = _ - - <%= xmlTree1.(0) %> - <%= child2 %> - - -' Compare Child1 identity. -Console.WriteLine("Child1 was {0}", _ - IIf(xmlTree1.Element("Child1") Is xmlTree2.Element("Child1"), _ - "attached", "cloned")) - -' Compare Child2 identity. -Console.WriteLine("Child2 was {0}", _ - IIf(child2 Is xmlTree2.Element("Child2"), _ - "attached", "cloned")) -``` - - This example produces the following output: - -```console -Child1 was cloned -Child2 was attached -``` - -## See also - -- [Creating XML Trees (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/creating-xml-trees.md) diff --git a/docs/visual-basic/programming-guide/concepts/linq/preserving-white-space-while-loading-or-parsing-xml.md b/docs/visual-basic/programming-guide/concepts/linq/preserving-white-space-while-loading-or-parsing-xml.md deleted file mode 100644 index 2bd69577114d7..0000000000000 --- a/docs/visual-basic/programming-guide/concepts/linq/preserving-white-space-while-loading-or-parsing-xml.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: "Preserving White Space while Loading or Parsing XML2" -ms.date: 07/20/2015 -ms.assetid: ef6518e0-2c8d-462c-8b92-a16e9dc737ad ---- -# Preserving White Space while Loading or Parsing XML -This topic describes how to control the white space behavior of [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)]. - - A common scenario is to read indented XML, create an in-memory XML tree without any white space text nodes (that is, not preserving white space), perform some operations on the XML, and then save the XML with indentation. When you serialize the XML with formatting, only significant white space in the XML tree is preserved. This is the default behavior for [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)]. - - Another common scenario is to read and modify XML that has already been intentionally indented. You might not want to change this indentation in any way. To do this in [!INCLUDE[sqltecxlinq](~/includes/sqltecxlinq-md.md)], you preserve white space when you load or parse the XML and disable formatting when you serialize the XML. - - This topic describes the white space behavior of methods that populate XML trees. For information about controlling white space when you serialize XML trees, see [Preserving White Space While Serializing](../../../../visual-basic/programming-guide/concepts/linq/preserving-white-space-while-serializing.md). - -## Behavior of Methods that Populate XML Trees - The following methods in the and classes populate an XML tree. You can populate an XML tree from a file, a , an , or a string: - -- - -- - -- - -- - - If the method does not take as an argument, the method will not preserve insignificant white space. - - In most cases, if the method takes as an argument, you can optionally preserve insignificant white space as text nodes in the XML tree. However, if the method is loading the XML from an , then the determines whether white space will be preserved or not. Setting will have no effect. - - With these methods, if white space is preserved, insignificant white space is inserted into the XML tree as nodes. If white space is not preserved, text nodes are not inserted. - - You can create an XML tree by using an . Nodes that are written to the are populated in the tree. However, when you build an XML tree using this method, all nodes are preserved, regardless of whether the node is white space or not, or whether the white space is significant or not. - -## See also - -- [Parsing XML (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/parsing-xml.md) From 2ded29b14ced7879db07b75ba150460ae5b95ceb Mon Sep 17 00:00:00 2001 From: Maira Wenzel Date: Tue, 25 Feb 2020 23:57:52 -0800 Subject: [PATCH 2/6] small edits --- docs/standard/linq/catch-parsing-errors.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/standard/linq/catch-parsing-errors.md b/docs/standard/linq/catch-parsing-errors.md index fcf0f933e974d..040391725187e 100644 --- a/docs/standard/linq/catch-parsing-errors.md +++ b/docs/standard/linq/catch-parsing-errors.md @@ -1,5 +1,6 @@ --- title: "How to catch parsing errors - LINQ to XML" +description: Learn how to detect badly formed or invalid XML. ms.date: 7/20/2015 dev_langs: - "csharp" @@ -9,7 +10,7 @@ ms.assetid: bfb612d4-5605-48ef-8c93-915cf9d5dcfb # How to catch parsing errors (LINQ to XML) -This article shows how to detect badly formed or invalid XML. +This article shows how to detect badly formed or invalid XML in C# or Visual Basic. LINQ to XML is implemented using . If badly formed or invalid XML is passed to LINQ to XML, the underlying class will throw an exception. The various methods that parse XML, such as , do not catch the exception; the exception can then be caught by your application. From 693a79bda71c587ab9a351be9530729b3d568b54 Mon Sep 17 00:00:00 2001 From: Maira Wenzel Date: Tue, 25 Feb 2020 23:59:02 -0800 Subject: [PATCH 3/6] small edits --- docs/standard/linq/create-tree-xmlreader.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/standard/linq/create-tree-xmlreader.md b/docs/standard/linq/create-tree-xmlreader.md index 79c81ed00e1a2..dab1d2c7ffb1d 100644 --- a/docs/standard/linq/create-tree-xmlreader.md +++ b/docs/standard/linq/create-tree-xmlreader.md @@ -1,5 +1,6 @@ --- title: "How to create a tree from an XmlReader - LINQ to XML" +description: Learn how to create an XML tree directly from an XmlReader. ms.date: 07/20/2015 dev_langs: - "csharp" @@ -9,7 +10,7 @@ ms.assetid: 60951c9c-7087-406c-b5bb-c60e58609b21 # How to create a tree from an XmlReader (LINQ to XML) -This article shows how to create an XML tree directly from an . To create an from an , you position the on an element node. The will skip comments and processing instructions, but if the is positioned on a text node, an error will be thrown. To avoid such errors, position the on an element before you create an XML tree from the . +This article shows how to create an XML tree directly from an in C# or Visual Basic. To create an from an , you position the on an element node. The will skip comments and processing instructions, but if the is positioned on a text node, an error will be thrown. To avoid such errors, position the on an element before you create an XML tree from the . ## Example: Load XElement object from an XmlReader object From a6162a106a9172c49bfbc256f9d7b17e8b889209 Mon Sep 17 00:00:00 2001 From: Maira Wenzel Date: Wed, 26 Feb 2020 00:02:09 -0800 Subject: [PATCH 4/6] use link --- docs/standard/linq/create-tree-xmlreader.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/linq/create-tree-xmlreader.md b/docs/standard/linq/create-tree-xmlreader.md index dab1d2c7ffb1d..0ca11cc809009 100644 --- a/docs/standard/linq/create-tree-xmlreader.md +++ b/docs/standard/linq/create-tree-xmlreader.md @@ -16,7 +16,7 @@ This article shows how to create an XML tree directly from an object. +The following code creates a object, reads nodes until it finds the first element node, and loads the object. ```csharp XmlReader r = XmlReader.Create("books.xml"); From 506e224198d4c296f6b326d8b6a681a54456df4e Mon Sep 17 00:00:00 2001 From: Maira Wenzel Date: Wed, 26 Feb 2020 00:08:27 -0800 Subject: [PATCH 5/6] small edits --- docs/standard/linq/load-xml-file.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/standard/linq/load-xml-file.md b/docs/standard/linq/load-xml-file.md index a6a0e2890bc23..c2f99feb1f667 100644 --- a/docs/standard/linq/load-xml-file.md +++ b/docs/standard/linq/load-xml-file.md @@ -1,5 +1,6 @@ --- title: "How to load XML from a file - LINQ to XML" +description: Learn how to load XML from a file. ms.date: 07/20/2015 dev_langs: - "csharp" @@ -9,7 +10,7 @@ ms.assetid: 3ed38487-8028-4209-9872-c8dce0ed4dfe # How to load XML from a file (LINQ to XML) -This article shows how to load XML from a file using the method. +This article shows how to load XML from a file in C# and Visual Basic using the method. ## Example: Load XML document from a file From 7a2dfb6351daa4783e48cfc5d9d374757ab6c49b Mon Sep 17 00:00:00 2001 From: Maira Wenzel Date: Wed, 26 Feb 2020 00:13:38 -0800 Subject: [PATCH 6/6] add missing desciption --- docs/standard/linq/preserve-white-space-loading-parsing-xml.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/standard/linq/preserve-white-space-loading-parsing-xml.md b/docs/standard/linq/preserve-white-space-loading-parsing-xml.md index 8491a9ed2ef37..4597c00f6ab8c 100644 --- a/docs/standard/linq/preserve-white-space-loading-parsing-xml.md +++ b/docs/standard/linq/preserve-white-space-loading-parsing-xml.md @@ -1,5 +1,6 @@ --- title: "Preserve white space while loading or parsing XML - LINQ to XML" +description: Learn how to control the white-space behavior of methods that populate XML trees. ms.date: 07/20/2015 ms.assetid: f3ff58c4-55aa-4fcd-b933-e3a2ee6e706c ---