From c626ed3df93f1d8c33ca73f48ae0fd3a80a0a418 Mon Sep 17 00:00:00 2001 From: jameshkramer Date: Mon, 6 Apr 2020 15:26:54 -0700 Subject: [PATCH 01/13] 20). Add topic files 51 to 54 --- docs/standard/linq/catch-parsing-errors.md | 2 +- .../linq/control-namespace-prefixes.md | 2 +- docs/standard/linq/filter-optional-element.md | 184 ++++++++++++++++++ .../standard/linq/find-all-nodes-namespace.md | 141 ++++++++++++++ .../find-descendants-specific-element-name.md | 165 ++++++++++++++++ .../linq/find-element-specific-attribute.md | 4 +- .../find-element-specific-child-element.md | 96 +++++++++ .../linq/linq-xml-classes-overview.md | 2 +- docs/standard/linq/parse-string.md | 2 +- .../linq/retrieve-shallow-value-element.md | 4 +- ...e-xml-file-consolidated-purchase-orders.md | 2 +- .../serialize-files-textwriters-xmlwriters.md | 2 +- docs/standard/linq/sort-elements.md | 104 ++++++++++ docs/standard/linq/work-global-namespaces.md | 2 +- .../linq/write-queries-complex-filtering.md | 127 ++++++++++++ .../standard/linq/xdocument-class-overview.md | 2 +- 16 files changed, 829 insertions(+), 12 deletions(-) create mode 100644 docs/standard/linq/filter-optional-element.md create mode 100644 docs/standard/linq/find-all-nodes-namespace.md create mode 100644 docs/standard/linq/find-descendants-specific-element-name.md create mode 100644 docs/standard/linq/find-element-specific-child-element.md create mode 100644 docs/standard/linq/sort-elements.md create mode 100644 docs/standard/linq/write-queries-complex-filtering.md diff --git a/docs/standard/linq/catch-parsing-errors.md b/docs/standard/linq/catch-parsing-errors.md index 00207eaaaa1fc..cbaac24489505 100644 --- a/docs/standard/linq/catch-parsing-errors.md +++ b/docs/standard/linq/catch-parsing-errors.md @@ -12,7 +12,7 @@ ms.assetid: bfb612d4-5605-48ef-8c93-915cf9d5dcfb 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. +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 , don't catch the exception; the exception can then be caught by your application. ## Example: Parse invalid XML diff --git a/docs/standard/linq/control-namespace-prefixes.md b/docs/standard/linq/control-namespace-prefixes.md index 04efa8dfb2ae4..f63a9abe7b636 100644 --- a/docs/standard/linq/control-namespace-prefixes.md +++ b/docs/standard/linq/control-namespace-prefixes.md @@ -12,7 +12,7 @@ ms.assetid: 64de5186-b81a-4ddd-8327-8693df59a01b This article describes how to control namespace prefixes when serializing an XML tree in C# and Visual Basic. -In many situations, it is not necessary to control namespace prefixes. However, certain XML programming tools require it. For example, you might be manipulating an XSLT style sheet or a XAML document that contains embedded XPath expressions that refer to specific namespace prefixes. In such a case, it is important that the document be serialized with those prefixes. This is a common reason for controlling namespace prefixes. +In many situations, it isn't necessary to control namespace prefixes. However, certain XML programming tools require it. For example, you might be manipulating an XSLT style sheet or a XAML document that contains embedded XPath expressions that refer to specific namespace prefixes. In such a case, it is important that the document be serialized with those prefixes. This is a common reason for controlling namespace prefixes. Another reason is that you want users to edit the XML document manually, and you want to create namespace prefixes that are convenient for the user to type. For example, you might be generating an XSD document. Conventions for schemas suggest that you use either `xs` or `xsd` as the prefix for the schema namespace. diff --git a/docs/standard/linq/filter-optional-element.md b/docs/standard/linq/filter-optional-element.md new file mode 100644 index 0000000000000..149589e4339af --- /dev/null +++ b/docs/standard/linq/filter-optional-element.md @@ -0,0 +1,184 @@ +--- +title: How to filter on an optional element - LINQ to XML +description: You can write a search for a child element in such a way that the search doesn't trigger an exception when the element doesn't exist. +ms.date: 07/20/2015 +dev_langs: + - "csharp" + - "vb" +ms.assetid: f99e2f93-fca5-403f-8a0c-770761d4905a +--- + +# How to filter on an optional element (LINQ to XML) + +Sometimes you want to filter for an element even though you aren't sure it exists in your XML document. You can write your search so that, even if the particular element doesn't have the child element, you don't trigger a null reference exception by filtering for it. + +## Example: Search that doesn't trigger an exception when the target element doesn't exist + +In the following example, the `Child5` element doesn't have a `Type` child element, but the query still executes correctly. The example uses the extension method. + +```csharp +XElement root = XElement.Parse(@" + + Child One Text + + + + Child Two Text + + + + Child Three Text + + + + Child Four Text + + + + Child Five Text + +"); +var cList = + from typeElement in root.Elements().Elements("Type") + where (string)typeElement.Attribute("Value") == "Yes" + select (string)typeElement.Parent.Element("Text"); +foreach(string str in cList) + Console.WriteLine(str); +``` + +```vb +Dim root As XElement = _ + + + Child One Text + + + + Child Two Text + + + + Child Three Text + + + + Child Four Text + + + + Child Five Text + + +Dim cList As IEnumerable(Of String) = _ + From typeElement In root.Elements(). _ + Where typeElement.@Value = "Yes" _ + Select typeElement.Parent..Value +Dim str As String +For Each str In cList + Console.WriteLine(str) +Next +``` + +The example produces this output: + +```output +Child One Text +Child Two Text +Child Four Text +``` + +## Example: Same search but for XML in a namespace + +The following example is the same query but for XML that's in a namespace. For more information, see [Namespaces overview](namespaces-overview.md). + +```csharp +XElement root = XElement.Parse(@" + + Child One Text + + + + Child Two Text + + + + Child Three Text + + + + Child Four Text + + + + Child Five Text + +"); +XNamespace ad = "http://www.adatum.com"; +var cList = + from typeElement in root.Elements().Elements(ad + "Type") + where (string)typeElement.Attribute("Value") == "Yes" + select (string)typeElement.Parent.Element(ad + "Text"); +foreach (string str in cList) + Console.WriteLine(str); +``` + +```vb +Imports + +Module Module1 + Sub Main() + Dim root As XElement = _ + + + Child One Text + + + + Child Two Text + + + + Child Three Text + + + + Child Four Text + + + + Child Five Text + + + Dim cList As IEnumerable(Of String) = _ + From typeElement In root.Elements(). _ + Where typeElement.@Value = "Yes" _ + Select typeElement.Parent..Value + Dim str As String + For Each str In cList + Console.WriteLine(str) + Next + End Sub +End Module +``` + +The example produces this output: + +```output +Child One Text +Child Two Text +Child Four Text +``` + +## See also + +- +- +- +- [Standard Query Operators Overview (C#)](../../csharp/programming-guide/concepts/linq/standard-query-operators-overview.md) +- [Projection Operations (C#)](../../csharp/programming-guide/concepts/linq/projection-operations.md) +- [Basic Queries (LINQ to XML) (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/basic-queries-linq-to-xml.md) +- [XML Child Axis Property](../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md) +- [XML Attribute Axis Property](../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md) +- [XML Value Property](../../visual-basic/language-reference/xml-axis/xml-value-property.md) +- [Standard Query Operators Overview (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/standard-query-operators-overview.md) +- [Projection Operations (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/projection-operations.md) diff --git a/docs/standard/linq/find-all-nodes-namespace.md b/docs/standard/linq/find-all-nodes-namespace.md new file mode 100644 index 0000000000000..98b1bc7400bb5 --- /dev/null +++ b/docs/standard/linq/find-all-nodes-namespace.md @@ -0,0 +1,141 @@ +--- +title: How to find all nodes in a namespace - LINQ to XML +description: You can filter on the namespace of each element or attribute to find all nodes in that particular namespace. +ms.date: 07/20/2015 +dev_langs: + - "csharp" + - "vb" +ms.assetid: 3a38b913-a53e-4d0e-a19d-8782bffd3364 +--- + +# How to find all nodes in a namespace (LINQ to XML) + +You can filter on the namespace of each element or attribute to find all nodes in that particular namespace. + +## Example: Create an XML tree with two namespaces, and print contents of one + +The following example creates an XML tree with two namespaces. It then iterates through the tree and prints the names of all the elements and attributes in one of those namespaces. + +```csharp +string markup = @" + abc + def + ghi + + jkl + mno + +"; +XElement xmlTree = XElement.Parse(markup); +Console.WriteLine("Nodes in the http://www.adventure-works.com namespace"); +IEnumerable awElements = + from el in xmlTree.Descendants() + where el.Name.Namespace == "http://www.adventure-works.com" + select el; +foreach (XElement el in awElements) + Console.WriteLine(el.Name.ToString()); +``` + +```vb +Imports +Imports + +Module Module1 + Sub Main() + Dim xmlTree As XElement = _ + + abc + def + ghi + + jkl + mno + + + Console.WriteLine("Nodes in the http://www.adventure-works.com namespace") + Dim awElements As IEnumerable(Of XElement) = _ + From el In xmlTree.Descendants() _ + Where (el.Name.Namespace = GetXmlNamespace(aw)) _ + Select el + For Each el As XElement In awElements + Console.WriteLine(el.Name.ToString()) + Next + End Sub +End Module +``` + +The example produces this output: + +```output +Nodes in the http://www.adventure-works.com namespace +{http://www.adventure-works.com}Child3 +{http://www.adventure-works.com}GrandChild2 +``` + +## Example: Create an XML tree from one of two namespaces contained in a file + +XML document [Sample XML file: Consolidated purchase orders](sample-xml-file-consolidated-purchase-orders.md) contains purchase orders in two different namespaces. The following query creates a new tree from the elements of one of them. + +```csharp +XDocument cpo = XDocument.Load("ConsolidatedPurchaseOrders.xml"); +XNamespace aw = "http://www.adventure-works.com"; +XElement newTree = new XElement("Root", + from el in cpo.Root.Elements() + where el.Name.Namespace == aw + select el +); +Console.WriteLine(newTree); +``` + +```vb +Imports + +Module Module1 + Sub Main() + Dim cpo As XDocument = XDocument.Load("ConsolidatedPurchaseOrders.xml") + Dim newTree As XElement = _ + + <%= From el In cpo.Root.Elements() _ + Where el.Name.Namespace = GetXmlNamespace(aw) _ + Select el %> + + Console.WriteLine(newTree) + End Sub +End Module +``` + +The example produces this output: + +```xml + + + + Chris Preston + 123 Main St. + Seattle + WA + 98113 + USA + + + Chris Preston + 123 Main St. + Seattle + WA + 98113 + USA + + Ship only complete order. + + Litware Networking Card + 1 + 20.99 + + + Litware 17in LCD Monitor + 1 + 199.99 + + + +``` diff --git a/docs/standard/linq/find-descendants-specific-element-name.md b/docs/standard/linq/find-descendants-specific-element-name.md new file mode 100644 index 0000000000000..7af924fe04d90 --- /dev/null +++ b/docs/standard/linq/find-descendants-specific-element-name.md @@ -0,0 +1,165 @@ +--- +title: How to find descendants with a specific element name - LINQ to XML +description: To find all descendants that have a specific name, it is easier to use XContainer.Descendants than to iterate through all the descendants. +ms.date: 07/20/2015 +ms.assetid: f684da20-bee9-47f5-9607-7e3fd7e67470 +--- + +# How to find descendants with a specific element name (LINQ to XML) + +Sometimes you want to find all descendants with a specific name. You could write code to iterate through all of the descendants, but it is easier to use the axis. + +## Example: Find descendants with a specific element name + +The following example shows how to find descendants with a specific element name. + +```csharp +XElement root = XElement.Parse(@" + + + Some text + + + + that's broken up into + + + + + multiple segments. + + + +"); +IEnumerable textSegs = + from seg in root.Descendants("t") + select (string)seg; + +string str = textSegs.Aggregate(new StringBuilder(), + (sb, i) => sb.Append(i), + sp => sp.ToString() +); + +Console.WriteLine(str); +``` + +```vb +Dim root As XElement = _ + + + + Some text + + + + that's broken up into + + + + + multiple segments. + + + + + +Dim textSegs As IEnumerable(Of String) = _ + From seg In root... _ + Select seg.Value + +Dim str As String = textSegs.Aggregate( _ + New StringBuilder, _ + Function(sb, i) sb.Append(i), _ + Function(sb) sb.ToString) + +Console.WriteLine(str) +``` + +The example produces this output: + +```output +Some text that's broken up into multiple segments. +``` + +## Example: Find when the XML is in a namespace + +The following example shows the same query for XML that's in a namespace. For more information, see [Namespaces overview](namespaces-overview.md). + +```csharp +XElement root = XElement.Parse(@" + + + Some text + + + + that's broken up into + + + + + multiple segments. + + + +"); +XNamespace ad = "http://www.adatum.com"; +IEnumerable textSegs = + from seg in root.Descendants(ad + "t") + select (string)seg; + +string str = textSegs.Aggregate(new StringBuilder(), + (sb, i) => sb.Append(i), + sp => sp.ToString() +); + +Console.WriteLine(str); +``` + +```vb +Imports + +Module Module1 + Sub Main() + Dim root As XElement = _ + + + + Some text + + + + that's broken up into + + + + + multiple segments. + + + + + + Dim textSegs As IEnumerable(Of String) = _ + From seg In root... _ + Select seg.Value + + Dim str As String = textSegs.Aggregate( _ + New StringBuilder, _ + Function(sb, i) sb.Append(i), _ + Function(sb) sb.ToString) + + Console.WriteLine(str) + End Sub +End Module +``` + +The example produces this output: + +```output +Some text that's broken up into multiple segments. +``` + +## See also + +- diff --git a/docs/standard/linq/find-element-specific-attribute.md b/docs/standard/linq/find-element-specific-attribute.md index e249b371f9964..1dd33254ff07f 100644 --- a/docs/standard/linq/find-element-specific-attribute.md +++ b/docs/standard/linq/find-element-specific-attribute.md @@ -49,9 +49,9 @@ The example produces this output: ``` -## Example: Find an element in XML that is in a namespace +## Example: Find an element in XML that's in a namespace -The following example shows the same query, but for XML that is in a namespace. It uses XML document [Sample XML file: typical purchase order in a namespace](sample-xml-file-typical-purchase-order-namespace.md). +The following example shows the same query, but for XML that's in a namespace. It uses XML document [Sample XML file: typical purchase order in a namespace](sample-xml-file-typical-purchase-order-namespace.md). For more information about namespaces, see [Namespaces overview](namespaces-overview.md). diff --git a/docs/standard/linq/find-element-specific-child-element.md b/docs/standard/linq/find-element-specific-child-element.md new file mode 100644 index 0000000000000..468b0aa773bfc --- /dev/null +++ b/docs/standard/linq/find-element-specific-child-element.md @@ -0,0 +1,96 @@ +--- +title: How to find an element with a specific child element - LINQ to XML +description: Find an element whose child element has a specific value +ms.date: 07/20/2015 +dev_langs: + - "csharp" + - "vb" +ms.assetid: 00cf5555-374e-4369-bf93-7bd2e7f21db3 +--- + +# How to find an element with a specific child element (LINQ to XML) + +This article shows how to find an element whose child element has a specific value. + +## Example: Find an element whose child element has a specific value + +The example finds the `Test` element whose `CommandLine` child element has a value of "Examp2.EXE". The example uses XML document [Sample XML file: Test configuration](sample-xml-file-test-configuration.md). + +```csharp +XElement root = XElement.Load("TestConfig.xml"); +IEnumerable tests = + from el in root.Elements("Test") + where (string)el.Element("CommandLine") == "Examp2.EXE" + select el; +foreach (XElement el in tests) + Console.WriteLine((string)el.Attribute("TestId")); +``` + +```vb +Dim root As XElement = XElement.Load("TestConfig.xml") +Dim tests As IEnumerable(Of XElement) = _ + From el In root. _ + Where el..Value = "Examp2.EXE" _ + Select el +For Each el as XElement In tests + Console.WriteLine(el.@TestId) +Next +``` + +The example produces this output: + +```output +0002 +0006 +``` + +Note that the Visual Basic version of the code uses the [XML Child axis property](../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md), the [XML Attribute axis property](../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md), and the [XML Value property](../../visual-basic/language-reference/xml-axis/xml-value-property.md). + +## Example: Find when the XML is in a namespace + +The following example does the same as the previous one, but for XML that's in a namespace. The example uses XML document [Sample XML file: Test configuration in a namespace](sample-xml-file-test-configuration-namespace.md). + +For more information, see [Namespaces overview](namespaces-overview.md). + +```csharp +XElement root = XElement.Load("TestConfigInNamespace.xml"); +XNamespace ad = "http://www.adatum.com"; +IEnumerable tests = + from el in root.Elements(ad + "Test") + where (string)el.Element(ad + "CommandLine") == "Examp2.EXE" + select el; +foreach (XElement el in tests) + Console.WriteLine((string)el.Attribute("TestId")); +``` + +```vb +Imports + +Module Module1 + Sub Main() + Dim root As XElement = XElement.Load("TestConfigInNamespace.xml") + Dim tests As IEnumerable(Of XElement) = _ + From el In root. _ + Where el..Value = "Examp2.EXE" _ + Select el + For Each el As XElement In tests + Console.WriteLine(el.@TestId) + Next + End Sub +End Module +``` + +The example produces this output: + +```output +0002 +0006 +``` + +## See also + +- +- +- [Standard Query Operators Overview (C#)](../../csharp/programming-guide/concepts/linq/standard-query-operators-overview.md) +- [Projection Operations (C#)](../../csharp/programming-guide/concepts/linq/projection-operations.md) +- [Standard Query Operators Overview (Visual Basic)](/../../visual-basic/programming-guide/concepts/linq/standard-query-operators-overview.md) diff --git a/docs/standard/linq/linq-xml-classes-overview.md b/docs/standard/linq/linq-xml-classes-overview.md index 052b9da19978f..d10ab7a36b1f7 100644 --- a/docs/standard/linq/linq-xml-classes-overview.md +++ b/docs/standard/linq/linq-xml-classes-overview.md @@ -94,4 +94,4 @@ it's possible, if necessary, to control namespace prefixes. In some circumstance ### XText class - represents a text node. In most cases, you do not have to use this class. This class is primarily used for mixed content. + represents a text node. In most cases, you don't have to use this class. This class is primarily used for mixed content. diff --git a/docs/standard/linq/parse-string.md b/docs/standard/linq/parse-string.md index 45db055060d44..a3131a7ae9b05 100644 --- a/docs/standard/linq/parse-string.md +++ b/docs/standard/linq/parse-string.md @@ -46,7 +46,7 @@ XElement contacts = XElement.Parse( Console.WriteLine(contacts); ``` -You can parse a string in Visual Basic in a similar manner. However, it is more efficient to use XML literals, as shown in following code, because XML literals do not suffer from the same performance penalties as parsing XML from a string. +You can parse a string in Visual Basic in a similar manner. However, it is more efficient to use XML literals, as shown in following code, because XML literals don't suffer from the same performance penalties as parsing XML from a string. By using XML literals, you can just copy and paste your XML into your Visual Basic program. diff --git a/docs/standard/linq/retrieve-shallow-value-element.md b/docs/standard/linq/retrieve-shallow-value-element.md index dc4b66d35dd49..44e914ce81529 100644 --- a/docs/standard/linq/retrieve-shallow-value-element.md +++ b/docs/standard/linq/retrieve-shallow-value-element.md @@ -1,6 +1,6 @@ --- title: How to retrieve the shallow value of an element - LINQ to XML -description: Use the `ShallowValue` extension method to retrieve the shallow value of an element. The shallow value is the value of that element only; that is, it does not include the values of descendant elements. +description: Use the `ShallowValue` extension method to retrieve the shallow value of an element. The shallow value is the value of that element only; that is, it doesn't include the values of descendant elements. ms.date: 07/20/2015 dev_langs: - "csharp" @@ -9,7 +9,7 @@ ms.assetid: 924a2699-72f6-4be1-aaa6-de62f8ec73b9 --- # How to retrieve the shallow value of an element (LINQ to XML) -This topic shows how to retrieve the shallow value of an element, which is the value of that element only, not including values of descendent elements. Retrieving the shallow value is useful when you want to select elements based on their content. +This article shows how to retrieve the shallow value of an element, which is the value of that element only, not including values of descendent elements. Retrieving the shallow value is useful when you want to select elements based on their content. When you use casting or the property to retrieve an element value, the value includes the descendants. To retrieve the shallow value you can use the `ShallowValue` extension method, as shown in the following example. The example declares an extension method that retrieves the shallow value of an element. It then uses the extension method in a query to list all elements that contain a calculated value. diff --git a/docs/standard/linq/sample-xml-file-consolidated-purchase-orders.md b/docs/standard/linq/sample-xml-file-consolidated-purchase-orders.md index 057197fc76e81..6727fe32092e5 100644 --- a/docs/standard/linq/sample-xml-file-consolidated-purchase-orders.md +++ b/docs/standard/linq/sample-xml-file-consolidated-purchase-orders.md @@ -90,7 +90,7 @@ The following XML file is used in various examples in the LINQ to XML documentat 98112 USA - Please do not deliver on Saturday. + Please don't deliver on Saturday. Computer Keyboard diff --git a/docs/standard/linq/serialize-files-textwriters-xmlwriters.md b/docs/standard/linq/serialize-files-textwriters-xmlwriters.md index d301b9c205c1b..cf1d78e1de654 100644 --- a/docs/standard/linq/serialize-files-textwriters-xmlwriters.md +++ b/docs/standard/linq/serialize-files-textwriters-xmlwriters.md @@ -13,7 +13,7 @@ You can serialize any XML component, including If you want to suppress formatting when serializing to a string, you can use the method. -The default behavior when serializing to a file is to format (indent) the resulting XML document. When you indent, the insignificant white space in the XML tree isn't preserved. To serialize with formatting, use one of the overloads of the following methods that do not take as an argument: +The default behavior when serializing to a file is to format (indent) the resulting XML document. When you indent, the insignificant white space in the XML tree isn't preserved. To serialize with formatting, use one of the overloads of the following methods that don't take as an argument: - - diff --git a/docs/standard/linq/sort-elements.md b/docs/standard/linq/sort-elements.md new file mode 100644 index 0000000000000..d720181fad4f5 --- /dev/null +++ b/docs/standard/linq/sort-elements.md @@ -0,0 +1,104 @@ +--- +title: How to sort elements - LINQ to XML +description: Wite a query that sorts its results +ms.date: 07/20/2015 +dev_langs: + - "csharp" + - "vb" +ms.assetid: aee6fbbc-81fd-4b3e-b40f-6ed7b3bd3fee +--- + +# How to sort elements (LINQ to XML) + +## Example: Write a query that sorts its results + +This example shows how to write a query that sorts its results. It uses XML document [Sample XML file: Numerical data](sample-xml-file-numerical-data.md). + +```csharp +XElement root = XElement.Load("Data.xml"); +IEnumerable prices = + from el in root.Elements("Data") + let price = (decimal)el.Element("Price") + orderby price + select price; +foreach (decimal el in prices) + Console.WriteLine(el); +``` + +```vb +Dim root As XElement = XElement.Load("Data.xml") +Dim prices As IEnumerable(Of Decimal) = _ + From el In root. _ + Let price = Convert.ToDecimal(el..Value) _ + Order By (price) _ + Select price +For Each el As Decimal In prices + Console.WriteLine(el) +Next +``` + +The example produces this output: + +```output +0.99 +4.95 +6.99 +24.50 +29.00 +66.00 +89.99 +``` + +## Example: Write a query in a namespace that sorts its results + +The following example shows the same query for XML that's in a namespace. It uses XML document [Sample XML file: Numerical data in a namespace](sample-xml-file-numerical-data-namespace.md). + +For more information, see [Namespaces overview](namespaces-overview.md). + +```csharp +XElement root = XElement.Load("DataInNamespace.xml"); +XNamespace aw = "http://www.adatum.com"; +IEnumerable prices = + from el in root.Elements(aw + "Data") + let price = (decimal)el.Element(aw + "Price") + orderby price + select price; +foreach (decimal el in prices) + Console.WriteLine(el); +``` + +```vb +Imports + +Module Module1 + Sub Main() + Dim root As XElement = XElement.Load("DataInNamespace.xml") + Dim prices As IEnumerable(Of Decimal) = _ + From el In root. _ + Let price = Convert.ToDecimal(el..Value) _ + Order By (price) _ + Select price + For Each el As Decimal In prices + Console.WriteLine(el) + Next + End Sub +End Module +``` + +The example produces this output: + +```output +0.99 +4.95 +6.99 +24.50 +29.00 +66.00 +89.99 +``` + +## See also + +- [Sorting Data (C#)](../../csharp/programming-guide/concepts/linq/sorting-data.md) +- [Sorting Data](../../visual-basic/programming-guide/concepts/linq/sorting-data.md) +- [Basic Queries (LINQ to XML) (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/basic-queries-linq-to-xml.md) diff --git a/docs/standard/linq/work-global-namespaces.md b/docs/standard/linq/work-global-namespaces.md index 523139b0331f2..368d58a7cf8a4 100644 --- a/docs/standard/linq/work-global-namespaces.md +++ b/docs/standard/linq/work-global-namespaces.md @@ -67,7 +67,7 @@ The example produces this output: ## Example: Declare a default namespace and use an embedded expression for the `Child` element -Namespaces that are declared in XML literals do not carry over into embedded expressions. The following example declares a default namespace, and then uses an embedded expression for the `Child` element. +Namespaces that are declared in XML literals don't carry over into embedded expressions. The following example declares a default namespace, and then uses an embedded expression for the `Child` element. ```vb Dim root As XElement = _ diff --git a/docs/standard/linq/write-queries-complex-filtering.md b/docs/standard/linq/write-queries-complex-filtering.md new file mode 100644 index 0000000000000..999665dc8bad4 --- /dev/null +++ b/docs/standard/linq/write-queries-complex-filtering.md @@ -0,0 +1,127 @@ +--- +title: How to write queries with complex filtering - LINQ to XML +description: Sometimes you want to write LINQ to XML queries with complex filters. For example, you might have to find all elements that have a child element with a particular name and value. +ms.date: 07/20/2015 +dev_langs: + - "csharp" + - "vb" +ms.assetid: 4065d901-cf89-4e47-8bf9-abb65acfb003 +--- + +# How to write queries with complex filtering (LINQ to XML) + +Sometimes you want to write LINQ to XML queries with complex filters. For example, you might have to find all elements that have a child element with a particular name and value. This article gives an example of writing a query with complex filtering. + +## Example: Find with a nested query in the `Where` clause + +This example shows how to find all `PurchaseOrder` elements that have: + +- a child `Address` element whose `Type` attribute equals "Shipping", and +- a child `State` element that equals "NY". + + It uses a nested query in the `Where` clause, and the `Any` operator returns `true` if the collection has any elements in it. The example uses XML document [Sample XML file: Multiple purchase orders](sample-xml-file-multiple-purchase-orders.md). + +For more information about the `Any` operator, see [Quantifier Operations (C#)](../../../docs/csharp/programming-guide/concepts/linq/quantifier-operations.md) and [Quantifier Operations (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/quantifier-operations.md). + +```csharp +XElement root = XElement.Load("PurchaseOrders.xml"); +IEnumerable purchaseOrders = + from el in root.Elements("PurchaseOrder") + where + (from add in el.Elements("Address") + where + (string)add.Attribute("Type") == "Shipping" && + (string)add.Element("State") == "NY" + select add) + .Any() + select el; +foreach (XElement el in purchaseOrders) + Console.WriteLine((string)el.Attribute("PurchaseOrderNumber")); +``` + +```vb +Dim root As XElement = XElement.Load("PurchaseOrders.xml") +Dim purchaseOrders As IEnumerable(Of XElement) = _ + From el In root. _ + Where _ + (From add In el.
_ + Where _ + add.@Type = "Shipping" And _ + add..Value = "NY" _ + Select add) _ + .Any() _ + Select el +For Each el As XElement In purchaseOrders + Console.WriteLine(el.@PurchaseOrderNumber) +Next +``` + +The example produces this output: + +```output +99505 +``` + +## Example: Find in XML that's in a namespace + +The following example shows the same query as above, but for XML that's in a namespace. For more information, see [Namespaces overview](namespaces-overview.md). + +This example uses XML document [Sample XML file: Multiple purchase orders in a namespace](sample-xml-file-multiple-purchase-orders-namespace.md). + +```csharp +XElement root = XElement.Load("PurchaseOrdersInNamespace.xml"); +XNamespace aw = "http://www.adventure-works.com"; +IEnumerable purchaseOrders = + from el in root.Elements(aw + "PurchaseOrder") + where + (from add in el.Elements(aw + "Address") + where + (string)add.Attribute(aw + "Type") == "Shipping" && + (string)add.Element(aw + "State") == "NY" + select add) + .Any() + select el; +foreach (XElement el in purchaseOrders) + Console.WriteLine((string)el.Attribute(aw + "PurchaseOrderNumber")); +``` + +```vb +Imports + +Module Module1 + Sub Main() + Dim root As XElement = XElement.Load("PurchaseOrdersInNamespace.xml") + Dim purchaseOrders As IEnumerable(Of XElement) = _ + From el In root. _ + Where _ + (From add In el. _ + Where _ + add.@aw:Type = "Shipping" And _ + add..Value = "NY" _ + Select add) _ + .Any() _ + Select el + For Each el As XElement In purchaseOrders + Console.WriteLine(el.@aw:PurchaseOrderNumber) + Next + End Sub +End Module +``` + +The example produces this output: + +```output +99505 +``` + +## See also + +- +- +- [Projection Operations (C#)](../../csharp/programming-guide/concepts/linq/projection-operations.md) +- [Quantifier Operations (C#)](../../csharp/programming-guide/concepts/linq/quantifier-operations.md) +- [XML Child Axis Property](../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md) +- [XML Attribute Axis Property](../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md) +- [XML Value Property](../../visual-basic/language-reference/xml-axis/xml-value-property.md) +- [Projection Operations (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/projection-operations.md) +- [Quantifier Operations (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/quantifier-operations.md) diff --git a/docs/standard/linq/xdocument-class-overview.md b/docs/standard/linq/xdocument-class-overview.md index 7fabd6911cdf3..fb7c4011e8f17 100644 --- a/docs/standard/linq/xdocument-class-overview.md +++ b/docs/standard/linq/xdocument-class-overview.md @@ -1,6 +1,6 @@ --- title: XDocument class overview -description: The LINQ to XML XDocument class contains the information necessary for a valid XML document. In many cases you do not require the functionality of an XDocument object and can use an XElement object instead. +description: The LINQ to XML XDocument class contains the information necessary for a valid XML document. In many cases you don't require the functionality of an XDocument object and can use an XElement object instead. ms.date: 07/20/2015 dev_langs: - "csharp" From 3f20657b4986c5f16f8d3861d268ce37547e33cb Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Thu, 9 Apr 2020 13:45:05 -0700 Subject: [PATCH 02/13] 20). Delete C# and VB files, add redirections --- .openpublishing.redirection.json | 40 +++++++ .../how-to-filter-on-an-optional-element.md | 98 --------------- .../how-to-find-all-nodes-in-a-namespace.md | 90 -------------- .../concepts/linq/how-to-sort-elements.md | 66 ---------- ...to-write-queries-with-complex-filtering.md | 71 ----------- .../standard/linq/xdocument-class-overview.md | 2 +- .../how-to-filter-on-an-optional-element.md | 113 ------------------ .../how-to-find-all-nodes-in-a-namespace.md | 108 ----------------- .../concepts/linq/how-to-sort-elements.md | 74 ------------ ...to-write-queries-with-complex-filtering.md | 82 ------------- 10 files changed, 41 insertions(+), 703 deletions(-) delete mode 100644 docs/csharp/programming-guide/concepts/linq/how-to-filter-on-an-optional-element.md delete mode 100644 docs/csharp/programming-guide/concepts/linq/how-to-find-all-nodes-in-a-namespace.md delete mode 100644 docs/csharp/programming-guide/concepts/linq/how-to-sort-elements.md delete mode 100644 docs/csharp/programming-guide/concepts/linq/how-to-write-queries-with-complex-filtering.md delete mode 100644 docs/visual-basic/programming-guide/concepts/linq/how-to-filter-on-an-optional-element.md delete mode 100644 docs/visual-basic/programming-guide/concepts/linq/how-to-find-all-nodes-in-a-namespace.md delete mode 100644 docs/visual-basic/programming-guide/concepts/linq/how-to-sort-elements.md delete mode 100644 docs/visual-basic/programming-guide/concepts/linq/how-to-write-queries-with-complex-filtering.md diff --git a/.openpublishing.redirection.json b/.openpublishing.redirection.json index 592748d65dc8e..05b6732d57088 100644 --- a/.openpublishing.redirection.json +++ b/.openpublishing.redirection.json @@ -1513,6 +1513,26 @@ "redirect_url": "/dotnet/standard/linq/query-xdocument-vs-query-xelement", "redirect_document_id": true }, + { + "source_path": "docs/csharp/programming-guide/concepts/linq/how-to-filter-on-an-optional-element.md", + "redirect_url": "/dotnet/standard/linq/filter-optional-element", + "redirect_document_id": true + }, + { + "source_path": "docs/csharp/programming-guide/concepts/linq/how-to-find-all-nodes-in-a-namespace.md", + "redirect_url": "/dotnet/standard/linq/find-all-nodes-namespace", + "redirect_document_id": true + }, + { + "source_path": "docs/csharp/programming-guide/concepts/linq/how-to-sort-elements.md", + "redirect_url": "/dotnet/standard/linq/sort-elements", + "redirect_document_id": true + }, + { + "source_path": "docs/csharp/programming-guide/concepts/linq/how-to-write-queries-with-complex-filtering.md", + "redirect_url": "/dotnet/standard/linq/write-queries-complex-filtering", + "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" @@ -4784,6 +4804,26 @@ "redirect_url": "/dotnet/standard/linq/query-xdocument-vs-query-xelement", "redirect_document_id": false }, + { + "source_path": "docs/visual-basic/programming-guide/concepts/linq/how-to-filter-on-an-optional-element.md", + "redirect_url": "/dotnet/standard/linq/filter-optional-element", + "redirect_document_id": false + }, + { + "source_path": "docs/visual-basic/programming-guide/concepts/linq/how-to-find-all-nodes-in-a-namespace.md", + "redirect_url": "/dotnet/standard/linq/find-all-nodes-namespace", + "redirect_document_id": false + }, + { + "source_path": "docs/visual-basic/programming-guide/concepts/linq/how-to-sort-elements.md", + "redirect_url": "/dotnet/standard/linq/sort-elements", + "redirect_document_id": false + }, + { + "source_path": "docs/visual-basic/programming-guide/concepts/linq/how-to-write-queries-with-complex-filtering.md", + "redirect_url": "/dotnet/standard/linq/write-queries-complex-filtering", + "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/how-to-filter-on-an-optional-element.md b/docs/csharp/programming-guide/concepts/linq/how-to-filter-on-an-optional-element.md deleted file mode 100644 index 0ca7eba03d96c..0000000000000 --- a/docs/csharp/programming-guide/concepts/linq/how-to-filter-on-an-optional-element.md +++ /dev/null @@ -1,98 +0,0 @@ ---- -title: "How to filter on an optional element (C#)" -ms.date: 07/20/2015 -ms.assetid: f99e2f93-fca5-403f-8a0c-770761d4905a ---- -# How to filter on an optional element (C#) -Sometimes you want to filter for an element even though you are not sure it exists in your XML document. The search should be executed so that if the particular element does not have the child element, you do not trigger a null reference exception by filtering for it. In the following example, the `Child5` element does not have a `Type` child element, but the query still executes correctly. - -## Example - This example uses the extension method. - -```csharp -XElement root = XElement.Parse(@" - - Child One Text - - - - Child Two Text - - - - Child Three Text - - - - Child Four Text - - - - Child Five Text - -"); -var cList = - from typeElement in root.Elements().Elements("Type") - where (string)typeElement.Attribute("Value") == "Yes" - select (string)typeElement.Parent.Element("Text"); -foreach(string str in cList) - Console.WriteLine(str); -``` - - This code produces the following output: - -```output -Child One Text -Child Two Text -Child Four Text -``` - -## Example - The following example shows the same query for XML that is in a namespace. For more information, see [Namespaces Overview (LINQ to XML) (C#)](namespaces-overview-linq-to-xml.md). - -```csharp -XElement root = XElement.Parse(@" - - Child One Text - - - - Child Two Text - - - - Child Three Text - - - - Child Four Text - - - - Child Five Text - -"); -XNamespace ad = "http://www.adatum.com"; -var cList = - from typeElement in root.Elements().Elements(ad + "Type") - where (string)typeElement.Attribute("Value") == "Yes" - select (string)typeElement.Parent.Element(ad + "Text"); -foreach (string str in cList) - Console.WriteLine(str); -``` - - This code produces the following output: - -```output -Child One Text -Child Two Text -Child Four Text -``` - -## See also - -- -- -- -- [Standard Query Operators Overview (C#)](./standard-query-operators-overview.md) -- [Projection Operations (C#)](./projection-operations.md) diff --git a/docs/csharp/programming-guide/concepts/linq/how-to-find-all-nodes-in-a-namespace.md b/docs/csharp/programming-guide/concepts/linq/how-to-find-all-nodes-in-a-namespace.md deleted file mode 100644 index 0192671b39ba7..0000000000000 --- a/docs/csharp/programming-guide/concepts/linq/how-to-find-all-nodes-in-a-namespace.md +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: "How to find all nodes in a namespace (C#)" -ms.date: 07/20/2015 -ms.assetid: 3a38b913-a53e-4d0e-a19d-8782bffd3364 ---- -# How to find all nodes in a namespace (C#) -You can filter on the namespace of each element or attribute to find all nodes in that particular namespace. - -## Example - The following example creates an XML tree with two namespaces. It then iterates through the tree and prints the names of all the elements and attributes in one of those namespaces. - -```csharp -string markup = @" - abc - def - ghi - - jkl - mno - -"; -XElement xmlTree = XElement.Parse(markup); -Console.WriteLine("Nodes in the http://www.adventure-works.com namespace"); -IEnumerable awElements = - from el in xmlTree.Descendants() - where el.Name.Namespace == "http://www.adventure-works.com" - select el; -foreach (XElement el in awElements) - Console.WriteLine(el.Name.ToString()); -``` - - This code produces the following output: - -```output -Nodes in the http://www.adventure-works.com namespace -{http://www.adventure-works.com}Child3 -{http://www.adventure-works.com}GrandChild2 -``` - -## Example - The XML file accessed by the following query contains purchase orders in two different namespaces. The query creates a new tree with just the elements in one of the namespaces. - - This example uses the following XML document: [Sample XML File: Consolidated Purchase Orders](./sample-xml-file-consolidated-purchase-orders.md). - -```csharp -XDocument cpo = XDocument.Load("ConsolidatedPurchaseOrders.xml"); -XNamespace aw = "http://www.adventure-works.com"; -XElement newTree = new XElement("Root", - from el in cpo.Root.Elements() - where el.Name.Namespace == aw - select el -); -Console.WriteLine(newTree); -``` - - This code produces the following output: - -```xml - - - - Chris Preston - 123 Main St. - Seattle - WA - 98113 - USA - - - Chris Preston - 123 Main St. - Seattle - WA - 98113 - USA - - Ship only complete order. - - Litware Networking Card - 1 - 20.99 - - - Litware 17in LCD Monitor - 1 - 199.99 - - - -``` diff --git a/docs/csharp/programming-guide/concepts/linq/how-to-sort-elements.md b/docs/csharp/programming-guide/concepts/linq/how-to-sort-elements.md deleted file mode 100644 index c7c24496fe328..0000000000000 --- a/docs/csharp/programming-guide/concepts/linq/how-to-sort-elements.md +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: "How to sort elements (C#)" -ms.date: 07/20/2015 -ms.assetid: aee6fbbc-81fd-4b3e-b40f-6ed7b3bd3fee ---- -# How to sort elements (C#) -This example shows how to write a query that sorts its results. - -## Example - This example uses the following XML document: [Sample XML File: Numerical Data (LINQ to XML)](./sample-xml-file-numerical-data-linq-to-xml.md). - -```csharp -XElement root = XElement.Load("Data.xml"); -IEnumerable prices = - from el in root.Elements("Data") - let price = (decimal)el.Element("Price") - orderby price - select price; -foreach (decimal el in prices) - Console.WriteLine(el); -``` - - This code produces the following output: - -```output -0.99 -4.95 -6.99 -24.50 -29.00 -66.00 -89.99 -``` - -## Example - The following example shows the same query for XML that is in a namespace. For more information, see [Namespaces Overview (LINQ to XML) (C#)](namespaces-overview-linq-to-xml.md). - - This example uses the following XML document: [Sample XML File: Numerical Data in a Namespace](./sample-xml-file-numerical-data-in-a-namespace.md). - -```csharp -XElement root = XElement.Load("DataInNamespace.xml"); -XNamespace aw = "http://www.adatum.com"; -IEnumerable prices = - from el in root.Elements(aw + "Data") - let price = (decimal)el.Element(aw + "Price") - orderby price - select price; -foreach (decimal el in prices) - Console.WriteLine(el); -``` - - This code produces the following output: - -```output -0.99 -4.95 -6.99 -24.50 -29.00 -66.00 -89.99 -``` - -## See also - -- [Sorting Data (C#)](./sorting-data.md) diff --git a/docs/csharp/programming-guide/concepts/linq/how-to-write-queries-with-complex-filtering.md b/docs/csharp/programming-guide/concepts/linq/how-to-write-queries-with-complex-filtering.md deleted file mode 100644 index 3d25acfbfdfd9..0000000000000 --- a/docs/csharp/programming-guide/concepts/linq/how-to-write-queries-with-complex-filtering.md +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: "How to write queries with complex filtering (C#)" -ms.date: 07/20/2015 -ms.assetid: 4065d901-cf89-4e47-8bf9-abb65acfb003 ---- -# How to write queries with complex filtering (C#) -Sometimes you want to write LINQ to XML queries with complex filters. For example, you might have to find all elements that have a child element with a particular name and value. This topic gives an example of writing a query with complex filtering. - -## Example - This example shows how to find all `PurchaseOrder` elements that have a child `Address` element that has a `Type` attribute equal to "Shipping" and a child `State` element equal to "NY". It uses a nested query in the `Where` clause, and the `Any` operator returns `true` if the collection has any elements in it. For information about using method-based query syntax, see [Query Syntax and Method Syntax in LINQ](./query-syntax-and-method-syntax-in-linq.md). - - This example uses the following XML document: [Sample XML File: Multiple Purchase Orders (LINQ to XML)](./sample-xml-file-multiple-purchase-orders-linq-to-xml.md). - - For more information about the `Any` operator, see [Quantifier Operations (C#)](./quantifier-operations.md). - -```csharp -XElement root = XElement.Load("PurchaseOrders.xml"); -IEnumerable purchaseOrders = - from el in root.Elements("PurchaseOrder") - where - (from add in el.Elements("Address") - where - (string)add.Attribute("Type") == "Shipping" && - (string)add.Element("State") == "NY" - select add) - .Any() - select el; -foreach (XElement el in purchaseOrders) - Console.WriteLine((string)el.Attribute("PurchaseOrderNumber")); -``` - - This code produces the following output: - -```output -99505 -``` - -## Example - The following example shows the same query for XML that is in a namespace. For more information, see [Namespaces Overview (LINQ to XML) (C#)](namespaces-overview-linq-to-xml.md). - - This example uses the following XML document: [Sample XML File: Multiple Purchase Orders in a Namespace](./sample-xml-file-multiple-purchase-orders-in-a-namespace.md). - -```csharp -XElement root = XElement.Load("PurchaseOrdersInNamespace.xml"); -XNamespace aw = "http://www.adventure-works.com"; -IEnumerable purchaseOrders = - from el in root.Elements(aw + "PurchaseOrder") - where - (from add in el.Elements(aw + "Address") - where - (string)add.Attribute(aw + "Type") == "Shipping" && - (string)add.Element(aw + "State") == "NY" - select add) - .Any() - select el; -foreach (XElement el in purchaseOrders) - Console.WriteLine((string)el.Attribute(aw + "PurchaseOrderNumber")); -``` - - This code produces the following output: - -```output -99505 -``` - -## See also - -- -- -- [Projection Operations (C#)](./projection-operations.md) -- [Quantifier Operations (C#)](./quantifier-operations.md) diff --git a/docs/standard/linq/xdocument-class-overview.md b/docs/standard/linq/xdocument-class-overview.md index fb7c4011e8f17..93a62c0e24ce8 100644 --- a/docs/standard/linq/xdocument-class-overview.md +++ b/docs/standard/linq/xdocument-class-overview.md @@ -1,6 +1,6 @@ --- title: XDocument class overview -description: The LINQ to XML XDocument class contains the information necessary for a valid XML document. In many cases you don't require the functionality of an XDocument object and can use an XElement object instead. +description: The LINQ to XML XDocument class contains the information necessary for a valid XML document. In many cases, you don't need the functionality of an XDocument object and can use an XElement object instead. ms.date: 07/20/2015 dev_langs: - "csharp" diff --git a/docs/visual-basic/programming-guide/concepts/linq/how-to-filter-on-an-optional-element.md b/docs/visual-basic/programming-guide/concepts/linq/how-to-filter-on-an-optional-element.md deleted file mode 100644 index 78b1197c484de..0000000000000 --- a/docs/visual-basic/programming-guide/concepts/linq/how-to-filter-on-an-optional-element.md +++ /dev/null @@ -1,113 +0,0 @@ ---- -title: "How to: Filter on an Optional Element" -ms.date: 07/20/2015 -ms.assetid: a74b76ad-6889-4185-a189-d6ef2c63841e ---- -# How to: Filter on an Optional Element (Visual Basic) -Sometimes you want to filter for an element even though you are not sure it exists in your XML document. The search should be executed so that if the particular element does not have the child element, you do not trigger a null reference exception by filtering for it. In the following example, the `Child5` element does not have a `Type` child element, but the query still executes correctly. - -## Example - This example uses the extension method. - -```vb -Dim root As XElement = _ - - - Child One Text - - - - Child Two Text - - - - Child Three Text - - - - Child Four Text - - - - Child Five Text - - -Dim cList As IEnumerable(Of String) = _ - From typeElement In root.Elements(). _ - Where typeElement.@Value = "Yes" _ - Select typeElement.Parent..Value -Dim str As String -For Each str In cList - Console.WriteLine(str) -Next -``` - - This code produces the following output: - -```console -Child One Text -Child Two Text -Child Four Text -``` - -## Example - The following example shows the same query for XML that is in a namespace. For more information, see [Namespaces Overview (LINQ to XML) (Visual Basic)](namespaces-overview-linq-to-xml.md). - -```vb -Imports - -Module Module1 - Sub Main() - Dim root As XElement = _ - - - Child One Text - - - - Child Two Text - - - - Child Three Text - - - - Child Four Text - - - - Child Five Text - - - Dim cList As IEnumerable(Of String) = _ - From typeElement In root.Elements(). _ - Where typeElement.@Value = "Yes" _ - Select typeElement.Parent..Value - Dim str As String - For Each str In cList - Console.WriteLine(str) - Next - End Sub -End Module -``` - - This code produces the following output: - -```console -Child One Text -Child Two Text -Child Four Text -``` - -## See also - -- -- -- -- [Basic Queries (LINQ to XML) (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/basic-queries-linq-to-xml.md) -- [XML Child Axis Property](../../../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md) -- [XML Attribute Axis Property](../../../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md) -- [XML Value Property](../../../../visual-basic/language-reference/xml-axis/xml-value-property.md) -- [Standard Query Operators Overview (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/standard-query-operators-overview.md) -- [Projection Operations (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/projection-operations.md) diff --git a/docs/visual-basic/programming-guide/concepts/linq/how-to-find-all-nodes-in-a-namespace.md b/docs/visual-basic/programming-guide/concepts/linq/how-to-find-all-nodes-in-a-namespace.md deleted file mode 100644 index d763576e23dd3..0000000000000 --- a/docs/visual-basic/programming-guide/concepts/linq/how-to-find-all-nodes-in-a-namespace.md +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: "How to: Find All Nodes in a Namespace" -ms.date: 07/20/2015 -ms.assetid: b735d7da-5727-48a3-ab57-a16378adc32e ---- -# How to: Find All Nodes in a Namespace (Visual Basic) -You can filter on the namespace of each element or attribute to find all nodes in that particular namespace. - -## Example - The following example creates an XML tree with two namespaces. It then iterates through the tree and prints the names of all the elements and attributes in one of those namespaces. - -```vb -Imports -Imports - -Module Module1 - Sub Main() - Dim xmlTree As XElement = _ - - abc - def - ghi - - jkl - mno - - - Console.WriteLine("Nodes in the http://www.adventure-works.com namespace") - Dim awElements As IEnumerable(Of XElement) = _ - From el In xmlTree.Descendants() _ - Where (el.Name.Namespace = GetXmlNamespace(aw)) _ - Select el - For Each el As XElement In awElements - Console.WriteLine(el.Name.ToString()) - Next - End Sub -End Module -``` - - This code produces the following output: - -```console -Nodes in the http://www.adventure-works.com namespace -{http://www.adventure-works.com}Child3 -{http://www.adventure-works.com}GrandChild2 -``` - -## Example - The XML file accessed by the following query contains purchase orders in two different namespaces. The query creates a new tree with just the elements in one of the namespaces. - - This example uses the following XML document: [Sample XML File: Consolidated Purchase Orders](../../../../visual-basic/programming-guide/concepts/linq/sample-xml-file-consolidated-purchase-orders.md). - -```vb -Imports - -Module Module1 - Sub Main() - Dim cpo As XDocument = XDocument.Load("ConsolidatedPurchaseOrders.xml") - Dim newTree As XElement = _ - - <%= From el In cpo.Root.Elements() _ - Where el.Name.Namespace = GetXmlNamespace(aw) _ - Select el %> - - Console.WriteLine(newTree) - End Sub -End Module -``` - - This code produces the following output: - -```xml - - - - Chris Preston - 123 Main St. - Seattle - WA - 98113 - USA - - - Chris Preston - 123 Main St. - Seattle - WA - 98113 - USA - - Ship only complete order. - - Litware Networking Card - 1 - 20.99 - - - Litware 17in LCD Monitor - 1 - 199.99 - - - -``` - -## See also - -- [Basic Queries (LINQ to XML) (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/basic-queries-linq-to-xml.md) diff --git a/docs/visual-basic/programming-guide/concepts/linq/how-to-sort-elements.md b/docs/visual-basic/programming-guide/concepts/linq/how-to-sort-elements.md deleted file mode 100644 index 99d3da2199a15..0000000000000 --- a/docs/visual-basic/programming-guide/concepts/linq/how-to-sort-elements.md +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: "How to: Sort Elements" -ms.date: 07/20/2015 -ms.assetid: c2c09279-6c8a-482e-8e71-b1453a815052 ---- -# How to: Sort Elements (Visual Basic) -This example shows how to write a query that sorts its results. - -## Example - This example uses the following XML document: [Sample XML File: Numerical Data (LINQ to XML)](../../../../visual-basic/programming-guide/concepts/linq/sample-xml-file-numerical-data-linq-to-xml.md). - -```vb -Dim root As XElement = XElement.Load("Data.xml") -Dim prices As IEnumerable(Of Decimal) = _ - From el In root. _ - Let price = Convert.ToDecimal(el..Value) _ - Order By (price) _ - Select price -For Each el As Decimal In prices - Console.WriteLine(el) -Next -``` - - This code produces the following output: - -```console -0.99 -4.95 -6.99 -24.50 -29.00 -66.00 -89.99 -``` - -## Example - The following example shows the same query for XML that is in a namespace. For more information, see [Namespaces Overview (LINQ to XML) (Visual Basic)](namespaces-overview-linq-to-xml.md). - - This example uses the following XML document: [Sample XML File: Numerical Data in a Namespace](../../../../visual-basic/programming-guide/concepts/linq/sample-xml-file-numerical-data-in-a-namespace.md). - -```vb -Imports - -Module Module1 - Sub Main() - Dim root As XElement = XElement.Load("DataInNamespace.xml") - Dim prices As IEnumerable(Of Decimal) = _ - From el In root. _ - Let price = Convert.ToDecimal(el..Value) _ - Order By (price) _ - Select price - For Each el As Decimal In prices - Console.WriteLine(el) - Next - End Sub -End Module -``` - - This code produces the following output: - -```console -0.99 -4.95 -6.99 -24.50 -29.00 -66.00 -89.99 -``` - -## See also - -- [Sorting Data](../../../../visual-basic/programming-guide/concepts/linq/sorting-data.md) -- [Basic Queries (LINQ to XML) (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/basic-queries-linq-to-xml.md) diff --git a/docs/visual-basic/programming-guide/concepts/linq/how-to-write-queries-with-complex-filtering.md b/docs/visual-basic/programming-guide/concepts/linq/how-to-write-queries-with-complex-filtering.md deleted file mode 100644 index 7c7a940f38ac9..0000000000000 --- a/docs/visual-basic/programming-guide/concepts/linq/how-to-write-queries-with-complex-filtering.md +++ /dev/null @@ -1,82 +0,0 @@ ---- -title: "How to: Write Queries with Complex Filtering" -ms.date: 07/20/2015 -ms.assetid: bf286ffc-7990-4b00-a4eb-ee3d70129950 ---- -# How to: Write Queries with Complex Filtering (Visual Basic) -Sometimes you want to write LINQ to XML queries with complex filters. For example, you might have to find all elements that have a child element with a particular name and value. This topic gives an example of writing a query with complex filtering. - -## Example - This example shows how to find all `PurchaseOrder` elements that have a child `Address` element that has a `Type` attribute equal to "Shipping" and a child `State` element equal to "NY". It uses a nested query in the `Where` clause, and the `Any` operator returns `True` if the collection has any elements in it. - - This example uses the following XML document: [Sample XML File: Multiple Purchase Orders (LINQ to XML)](../../../../visual-basic/programming-guide/concepts/linq/sample-xml-file-multiple-purchase-orders-linq-to-xml.md). - - For more information about the `Any` operator, see [Quantifier Operations (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/quantifier-operations.md). - -```vb -Dim root As XElement = XElement.Load("PurchaseOrders.xml") -Dim purchaseOrders As IEnumerable(Of XElement) = _ - From el In root. _ - Where _ - (From add In el.
_ - Where _ - add.@Type = "Shipping" And _ - add..Value = "NY" _ - Select add) _ - .Any() _ - Select el -For Each el As XElement In purchaseOrders - Console.WriteLine(el.@PurchaseOrderNumber) -Next -``` - - This code produces the following output: - -```console -99505 -``` - -## Example - The following example shows the same query for XML that is in a namespace. For more information, see [Namespaces Overview (LINQ to XML) (Visual Basic)](namespaces-overview-linq-to-xml.md). - - This example uses the following XML document: [Sample XML File: Multiple Purchase Orders in a Namespace](../../../../visual-basic/programming-guide/concepts/linq/sample-xml-file-multiple-purchase-orders-in-a-namespace.md). - -```vb -Imports - -Module Module1 - Sub Main() - Dim root As XElement = XElement.Load("PurchaseOrdersInNamespace.xml") - Dim purchaseOrders As IEnumerable(Of XElement) = _ - From el In root. _ - Where _ - (From add In el. _ - Where _ - add.@aw:Type = "Shipping" And _ - add..Value = "NY" _ - Select add) _ - .Any() _ - Select el - For Each el As XElement In purchaseOrders - Console.WriteLine(el.@aw:PurchaseOrderNumber) - Next - End Sub -End Module -``` - - This code produces the following output: - -```console -99505 -``` - -## See also - -- -- -- [Basic Queries (LINQ to XML) (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/basic-queries-linq-to-xml.md) -- [XML Child Axis Property](../../../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md) -- [XML Attribute Axis Property](../../../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md) -- [XML Value Property](../../../../visual-basic/language-reference/xml-axis/xml-value-property.md) -- [Projection Operations (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/projection-operations.md) -- [Quantifier Operations (Visual Basic)](../../../../visual-basic/programming-guide/concepts/linq/quantifier-operations.md) From 39cac42d44dfa0256caa2625adbb8b3363889648 Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Fri, 10 Apr 2020 10:17:36 -0700 Subject: [PATCH 03/13] Update docs/standard/linq/filter-optional-element.md Co-Authored-By: Maira Wenzel --- docs/standard/linq/filter-optional-element.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/linq/filter-optional-element.md b/docs/standard/linq/filter-optional-element.md index 149589e4339af..18318c73a7d42 100644 --- a/docs/standard/linq/filter-optional-element.md +++ b/docs/standard/linq/filter-optional-element.md @@ -177,7 +177,7 @@ Child Four Text - [Standard Query Operators Overview (C#)](../../csharp/programming-guide/concepts/linq/standard-query-operators-overview.md) - [Projection Operations (C#)](../../csharp/programming-guide/concepts/linq/projection-operations.md) - [Basic Queries (LINQ to XML) (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/basic-queries-linq-to-xml.md) -- [XML Child Axis Property](../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md) +- [XML Child Axis Property (Visual Basic)](../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md) - [XML Attribute Axis Property](../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md) - [XML Value Property](../../visual-basic/language-reference/xml-axis/xml-value-property.md) - [Standard Query Operators Overview (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/standard-query-operators-overview.md) From 604cdc1ba688945d18f5c5a20f1d9f8ccefa3263 Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Fri, 10 Apr 2020 10:18:31 -0700 Subject: [PATCH 04/13] Update docs/standard/linq/filter-optional-element.md Co-Authored-By: Maira Wenzel --- docs/standard/linq/filter-optional-element.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/linq/filter-optional-element.md b/docs/standard/linq/filter-optional-element.md index 18318c73a7d42..64447e4cbed12 100644 --- a/docs/standard/linq/filter-optional-element.md +++ b/docs/standard/linq/filter-optional-element.md @@ -178,7 +178,7 @@ Child Four Text - [Projection Operations (C#)](../../csharp/programming-guide/concepts/linq/projection-operations.md) - [Basic Queries (LINQ to XML) (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/basic-queries-linq-to-xml.md) - [XML Child Axis Property (Visual Basic)](../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md) -- [XML Attribute Axis Property](../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md) +- [XML Attribute Axis Property (Visual Basic)](../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md) - [XML Value Property](../../visual-basic/language-reference/xml-axis/xml-value-property.md) - [Standard Query Operators Overview (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/standard-query-operators-overview.md) - [Projection Operations (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/projection-operations.md) From b0387bd8abd87cb4885a98eee8cfa69d992e1b75 Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Fri, 10 Apr 2020 10:18:55 -0700 Subject: [PATCH 05/13] Update docs/standard/linq/sort-elements.md Co-Authored-By: Maira Wenzel --- docs/standard/linq/sort-elements.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/linq/sort-elements.md b/docs/standard/linq/sort-elements.md index d720181fad4f5..354b3150f92bc 100644 --- a/docs/standard/linq/sort-elements.md +++ b/docs/standard/linq/sort-elements.md @@ -1,6 +1,6 @@ --- title: How to sort elements - LINQ to XML -description: Wite a query that sorts its results +description: Write a query that sorts its results. ms.date: 07/20/2015 dev_langs: - "csharp" From c49bfd44382890c87befc80aaf6abbf9d24e9d7b Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Fri, 10 Apr 2020 10:20:22 -0700 Subject: [PATCH 06/13] Update docs/standard/linq/sort-elements.md Co-Authored-By: Maira Wenzel --- docs/standard/linq/sort-elements.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/linq/sort-elements.md b/docs/standard/linq/sort-elements.md index 354b3150f92bc..bb7ca0e6ad948 100644 --- a/docs/standard/linq/sort-elements.md +++ b/docs/standard/linq/sort-elements.md @@ -100,5 +100,5 @@ The example produces this output: ## See also - [Sorting Data (C#)](../../csharp/programming-guide/concepts/linq/sorting-data.md) -- [Sorting Data](../../visual-basic/programming-guide/concepts/linq/sorting-data.md) +- [Sorting Data (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/sorting-data.md) - [Basic Queries (LINQ to XML) (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/basic-queries-linq-to-xml.md) From 29e9c3c3ccb249d1d8bc27db767e881ba3061074 Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Fri, 10 Apr 2020 10:26:21 -0700 Subject: [PATCH 07/13] Update docs/standard/linq/write-queries-complex-filtering.md Co-Authored-By: Maira Wenzel --- docs/standard/linq/write-queries-complex-filtering.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/linq/write-queries-complex-filtering.md b/docs/standard/linq/write-queries-complex-filtering.md index 999665dc8bad4..c94cdb0764c84 100644 --- a/docs/standard/linq/write-queries-complex-filtering.md +++ b/docs/standard/linq/write-queries-complex-filtering.md @@ -16,7 +16,7 @@ Sometimes you want to write LINQ to XML queries with complex filters. For exampl This example shows how to find all `PurchaseOrder` elements that have: -- a child `Address` element whose `Type` attribute equals "Shipping", and +- A child `Address` element whose `Type` attribute equals "Shipping". - a child `State` element that equals "NY". It uses a nested query in the `Where` clause, and the `Any` operator returns `true` if the collection has any elements in it. The example uses XML document [Sample XML file: Multiple purchase orders](sample-xml-file-multiple-purchase-orders.md). From 45a20ab7ad6e072d97a7945aadaa6be681bff167 Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Fri, 10 Apr 2020 10:26:47 -0700 Subject: [PATCH 08/13] Update docs/standard/linq/write-queries-complex-filtering.md Co-Authored-By: Maira Wenzel --- docs/standard/linq/write-queries-complex-filtering.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/linq/write-queries-complex-filtering.md b/docs/standard/linq/write-queries-complex-filtering.md index c94cdb0764c84..97998069af24b 100644 --- a/docs/standard/linq/write-queries-complex-filtering.md +++ b/docs/standard/linq/write-queries-complex-filtering.md @@ -17,7 +17,7 @@ Sometimes you want to write LINQ to XML queries with complex filters. For exampl This example shows how to find all `PurchaseOrder` elements that have: - A child `Address` element whose `Type` attribute equals "Shipping". -- a child `State` element that equals "NY". +- A child `State` element that equals "NY". It uses a nested query in the `Where` clause, and the `Any` operator returns `true` if the collection has any elements in it. The example uses XML document [Sample XML file: Multiple purchase orders](sample-xml-file-multiple-purchase-orders.md). From debf28293c3562dd450a4451ba587900f6668393 Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Fri, 10 Apr 2020 10:27:48 -0700 Subject: [PATCH 09/13] Update docs/standard/linq/write-queries-complex-filtering.md Co-Authored-By: Maira Wenzel --- docs/standard/linq/write-queries-complex-filtering.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/linq/write-queries-complex-filtering.md b/docs/standard/linq/write-queries-complex-filtering.md index 97998069af24b..4c617747881de 100644 --- a/docs/standard/linq/write-queries-complex-filtering.md +++ b/docs/standard/linq/write-queries-complex-filtering.md @@ -120,7 +120,7 @@ The example produces this output: - - [Projection Operations (C#)](../../csharp/programming-guide/concepts/linq/projection-operations.md) - [Quantifier Operations (C#)](../../csharp/programming-guide/concepts/linq/quantifier-operations.md) -- [XML Child Axis Property](../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md) +- [XML Child Axis Property (Visual Basic)](../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md) - [XML Attribute Axis Property](../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md) - [XML Value Property](../../visual-basic/language-reference/xml-axis/xml-value-property.md) - [Projection Operations (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/projection-operations.md) From be103e6e08dc85dead7d9c4c5d8fbf3e9a11e5a9 Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Fri, 10 Apr 2020 10:28:43 -0700 Subject: [PATCH 10/13] Update docs/standard/linq/write-queries-complex-filtering.md Co-Authored-By: Maira Wenzel --- docs/standard/linq/write-queries-complex-filtering.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/linq/write-queries-complex-filtering.md b/docs/standard/linq/write-queries-complex-filtering.md index 4c617747881de..3f816efccda87 100644 --- a/docs/standard/linq/write-queries-complex-filtering.md +++ b/docs/standard/linq/write-queries-complex-filtering.md @@ -19,7 +19,7 @@ This example shows how to find all `PurchaseOrder` elements that have: - A child `Address` element whose `Type` attribute equals "Shipping". - A child `State` element that equals "NY". - It uses a nested query in the `Where` clause, and the `Any` operator returns `true` if the collection has any elements in it. The example uses XML document [Sample XML file: Multiple purchase orders](sample-xml-file-multiple-purchase-orders.md). +It uses a nested query in the `Where` clause, and the `Any` operator returns `true` if the collection has any elements in it. The example uses XML document [Sample XML file: Multiple purchase orders](sample-xml-file-multiple-purchase-orders.md). For more information about the `Any` operator, see [Quantifier Operations (C#)](../../../docs/csharp/programming-guide/concepts/linq/quantifier-operations.md) and [Quantifier Operations (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/quantifier-operations.md). From 75038a7da7b4e1e43c5eff94d30ebb341e2d4e89 Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Fri, 10 Apr 2020 10:30:09 -0700 Subject: [PATCH 11/13] Update docs/standard/linq/write-queries-complex-filtering.md Co-Authored-By: Maira Wenzel --- docs/standard/linq/write-queries-complex-filtering.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/linq/write-queries-complex-filtering.md b/docs/standard/linq/write-queries-complex-filtering.md index 3f816efccda87..1d8cf3401f55d 100644 --- a/docs/standard/linq/write-queries-complex-filtering.md +++ b/docs/standard/linq/write-queries-complex-filtering.md @@ -121,7 +121,7 @@ The example produces this output: - [Projection Operations (C#)](../../csharp/programming-guide/concepts/linq/projection-operations.md) - [Quantifier Operations (C#)](../../csharp/programming-guide/concepts/linq/quantifier-operations.md) - [XML Child Axis Property (Visual Basic)](../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md) -- [XML Attribute Axis Property](../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md) +- [XML Attribute Axis Property (Visual Basic)](../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md) - [XML Value Property](../../visual-basic/language-reference/xml-axis/xml-value-property.md) - [Projection Operations (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/projection-operations.md) - [Quantifier Operations (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/quantifier-operations.md) From 30a476d6d74bd1613ec40937ffe591bb7fe88b06 Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Fri, 10 Apr 2020 10:31:06 -0700 Subject: [PATCH 12/13] Update docs/standard/linq/write-queries-complex-filtering.md Co-Authored-By: Maira Wenzel --- docs/standard/linq/write-queries-complex-filtering.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/linq/write-queries-complex-filtering.md b/docs/standard/linq/write-queries-complex-filtering.md index 1d8cf3401f55d..8f5aee5ca7f71 100644 --- a/docs/standard/linq/write-queries-complex-filtering.md +++ b/docs/standard/linq/write-queries-complex-filtering.md @@ -122,6 +122,6 @@ The example produces this output: - [Quantifier Operations (C#)](../../csharp/programming-guide/concepts/linq/quantifier-operations.md) - [XML Child Axis Property (Visual Basic)](../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md) - [XML Attribute Axis Property (Visual Basic)](../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md) -- [XML Value Property](../../visual-basic/language-reference/xml-axis/xml-value-property.md) +- [XML Value Property (Visual Basic)](../../visual-basic/language-reference/xml-axis/xml-value-property.md) - [Projection Operations (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/projection-operations.md) - [Quantifier Operations (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/quantifier-operations.md) From 0df459b8b1eaa21b1604f33d5b44cce2240e17c5 Mon Sep 17 00:00:00 2001 From: Jim Kramer Date: Fri, 10 Apr 2020 10:47:22 -0700 Subject: [PATCH 13/13] Update sort-elements.md --- docs/standard/linq/sort-elements.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/standard/linq/sort-elements.md b/docs/standard/linq/sort-elements.md index bb7ca0e6ad948..3a4676c324d60 100644 --- a/docs/standard/linq/sort-elements.md +++ b/docs/standard/linq/sort-elements.md @@ -10,6 +10,8 @@ ms.assetid: aee6fbbc-81fd-4b3e-b40f-6ed7b3bd3fee # How to sort elements (LINQ to XML) +You can sort your results when you query XML. This article provides two examples: the first sorts results for XML that *isn't* in a namespace, and the second does the same sort, but for XML that *is* in a namespace. + ## Example: Write a query that sorts its results This example shows how to write a query that sorts its results. It uses XML document [Sample XML file: Numerical data](sample-xml-file-numerical-data.md).