Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .openpublishing.redirection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,9 @@
{
"source_path": "docs/csharp/programming-guide/concepts/linq/serializing-with-an-xml-declaration.md",
"redirect_url": "/dotnet/standard/linq/serialize-xml-declaration",
"redirect_document_id": true
},
{
"source_path": "docs/csharp/programming-guide/concepts/linq/how-to-chain-axis-method-calls-linq-to-xml.md",
"redirect_url": "/dotnet/standard/linq/chain-axis-method-calls",
"redirect_document_id": true
Expand Down Expand Up @@ -1480,6 +1483,16 @@
"redirect_url": "/dotnet/standard/linq/retrieve-value-attribute",
"redirect_document_id": true
},
{
"source_path": "docs/csharp/programming-guide/concepts/linq/how-to-find-an-element-with-a-specific-attribute.md",
"redirect_url": "/dotnet/standard/linq/find-element-specific-attribute",
"redirect_document_id": true
},
{
"source_path": "docs/csharp/programming-guide/concepts/linq//how-to-retrieve-the-shallow-value-of-an-element.md",
"redirect_url": "/dotnet/standard/linq/retrieve-shallow-value-element",
"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"
Expand Down Expand Up @@ -4636,6 +4649,9 @@
{
"source_path": "docs/visual-basic/programming-guide/concepts/linq/serializing-with-an-xml-declaration.md",
"redirect_url": "/dotnet/standard/linq/serialize-xml-declaration",
"redirect_document_id": false
},
{
"source_path": "docs/visual-basic/programming-guide/concepts/linq/how-to-chain-axis-method-calls-linq-to-xml.md",
"redirect_url": "/dotnet/standard/linq/chain-axis-method-calls",
"redirect_document_id": false
Expand Down Expand Up @@ -4675,6 +4691,26 @@
"redirect_url": "/dotnet/standard/linq/retrieve-value-attribute",
"redirect_document_id": false
},
{
"source_path": "docs/visual-basic/programming-guide/concepts/linq/how-to-find-an-element-with-a-specific-attribute.md",
"redirect_url": "/dotnet/standard/linq/find-element-specific-attribute",
"redirect_document_id": false
},
{
"source_path": "docs/visual-basic/programming-guide/concepts/linq//how-to-retrieve-the-shallow-value-of-an-element.md",
"redirect_url": "/dotnet/standard/linq/retrieve-shallow-value-element",
"redirect_document_id": false
},
{
"source_path": "docs/visual-basic/programming-guide/concepts/linq/language-integrated-axes.md",
"redirect_url": "/dotnet/standard/linq/language-integrated-axes",
"redirect_document_id": false
},
{
"source_path": "docs/visual-basic/programming-guide/concepts/linq/querying-xml-trees.md",
"redirect_url": "/dotnet/standard/linq/query-xml-trees-overview",
"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"
Expand Down

This file was deleted.

This file was deleted.

107 changes: 107 additions & 0 deletions docs/standard/linq/find-element-specific-attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: How to find an element with a specific attribute - LINQ to XML
ms.date: 07/20/2015
dev_langs:
- "csharp"
- "vb"
ms.assetid: b92591aa-3cfb-490e-99f6-da8de335e362
---

# How to find an element with a specific attribute (LINQ to XML)

This article provides examples of how to find an element whose attribute has a specific value.

## Example: Find an element whose attribute has a specific value

The following example shows how to find the `Address` element that has a `Type` attribute with a value of "Billing". The example uses XML document [Sample XML file: Typical purchase order](sample-xml-file-typical-purchase-order.md).

```csharp
XElement root = XElement.Load("PurchaseOrder.xml");
IEnumerable<XElement> address =
from el in root.Elements("Address")
where (string)el.Attribute("Type") == "Billing"
select el;
foreach (XElement el in address)
Console.WriteLine(el);
```

```vb
Dim root As XElement = XElement.Load("PurchaseOrder.xml")
Dim address As IEnumerable(Of XElement) = _
From el In root.<Address> _
Where el.@Type = "Billing" _
Select el
For Each el As XElement In address
Console.WriteLine(el)
Next
```

The example produces this output:

```xml
<Address Type="Billing">
<Name>Tai Yee</Name>
<Street>8 Oak Avenue</Street>
<City>Old Town</City>
<State>PA</State>
<Zip>95819</Zip>
<Country>USA</Country>
</Address>
```

## Example: Find an element in XML that is 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).

For more information about namespaces, see [Namespaces overview](namespaces-overview.md).

```csharp
XElement root = XElement.Load("PurchaseOrderInNamespace.xml");
XNamespace aw = "http://www.adventure-works.com";
IEnumerable<XElement> address =
from el in root.Elements(aw + "Address")
where (string)el.Attribute(aw + "Type") == "Billing"
select el;
foreach (XElement el in address)
Console.WriteLine(el);
```

```vb
Imports <xmlns:aw='http://www.adventure-works.com'>

Module Module1
Sub Main()
Dim root As XElement = XElement.Load("PurchaseOrderInNamespace.xml")
Dim address As IEnumerable(Of XElement) = _
From el In root.<aw:Address> _
Where el.@aw:Type = "Billing" _
Select el
For Each el As XElement In address
Console.WriteLine(el)
Next
End Sub
End Module
```

The example produces this output::

```xml
<aw:Address aw:Type="Billing" xmlns:aw="http://www.adventure-works.com">
<aw:Name>Tai Yee</aw:Name>
<aw:Street>8 Oak Avenue</aw:Street>
<aw:City>Old Town</aw:City>
<aw:State>PA</aw:State>
<aw:Zip>95819</aw:Zip>
<aw:Country>USA</aw:Country>
</aw:Address>
```

## See also

- <xref:System.Xml.Linq.XElement.Attribute%2A>
- <xref:System.Xml.Linq.XContainer.Elements%2A>
- [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)
- [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)
21 changes: 21 additions & 0 deletions docs/standard/linq/language-integrated-axes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: "Language-integrated axes in Visual Basic - LINQ to XML"
description: LINQ to XML provides easy access to XML using the axes integrated into Visual Basic
ms.date: 07/20/2015
ms.assetid: d450a556-a134-4261-b011-44e399660894
---

# Language-integrated axes in Visual Basic (LINQ to XML)

Axis features are integrated into Visual Basic, making it easy to access XML. Many of the examples in the LINQ to XML documentation use these features, which are described in the articles listed in this table:

|Article|Description|
|-----------|-----------------|
|[XML Child Axis Property](../../visual-basic/language-reference/xml-axis/xml-child-axis-property.md)|Provides access to the children of one of the following: an <xref:System.Xml.Linq.XElement> object, an <xref:System.Xml.Linq.XDocument> object, a collection of <xref:System.Xml.Linq.XElement> objects, or a collection of <xref:System.Xml.Linq.XDocument> objects. This axis is equivalent to the <xref:System.Xml.Linq.XContainer.Elements%2A> axis.|
|[XML Descendant Axis Property](../../visual-basic/language-reference/xml-axis/xml-descendant-axis-property.md)|Provides access to the descendants of the following: an <xref:System.Xml.Linq.XElement> object, an <xref:System.Xml.Linq.XDocument> object, or a collection of <xref:System.Xml.Linq.XElement> objects. This axis is equivalent to the <xref:System.Xml.Linq.XContainer.Descendants%2A> axis.|
|[XML Attribute Axis Property](../../visual-basic/language-reference/xml-axis/xml-attribute-axis-property.md)|Provides access to an attribute of an <xref:System.Xml.Linq.XElement> object. This axis is roughly equivalent to the <xref:System.Xml.Linq.XElement.Attribute%2A> axis. This axis differs from the <xref:System.Xml.Linq.XElement.Attribute%2A> axis in that it returns the value of the attribute, not an <xref:System.Xml.Linq.XAttribute> object.|
|[Extension Indexer Property](../../visual-basic/language-reference/xml-axis/extension-indexer-property.md)|Provides access to individual elements in a collection.|

## See also

- [LINQ to XML axes overview](linq-xml-axes-overview.md)
35 changes: 35 additions & 0 deletions docs/standard/linq/query-xml-trees-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Query XML trees overview - LINQ to XML
ms.date: 07/20/2015
ms.assetid: 2e35c1ab-08c8-4378-9ca8-8ff344756eda
---

# Query XML trees overview (LINQ to XML)

After you've instantiated an XML tree, writing queries is the most effective way to extract data from the tree. Also, querying combined with functional construction enables you to generate a new XML document that has a different shape from the original document.

For background information about LINQ queries, see:

- [Introduction to LINQ Queries (C#)](../../csharp/programming-guide/concepts/linq/introduction-to-linq-queries.md)
- [Writing Your First LINQ Query (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/writing-your-first-linq-query.md)

## In this section

This section of articles provides information, including examples, about LINQ to XML queries. It comprises the following subsections:

|Topic|Description|
|-----------|-----------------|
|[Basic queries](find-element-specific-attribute.md)|Provides common examples of querying XML trees.|
|[Projections and transformations](work-dictionaries-linq-xml.md)|Provides common examples of projecting from and transforming XML trees.|
|[Advanced query techniques](join-two-collections.md)|Provides query techniques that are useful in more advanced scenarios.|
|[LINQ to XML for XPath users](comparison-xpath-linq-xml.md)|Presents a number of XPath expressions and their LINQ to XML equivalents.|
|[Pure functional transformations of XML](pure-functional-transformations.md)|Presents a small tutorial on writing queries in the style of functional programming.|

## See also

- [Language-Integrated Query (LINQ) (C#)](../../csharp/programming-guide/concepts/linq/index.md)
- [Introduction to LINQ Queries (C#)](../../csharp/programming-guide/concepts/linq/introduction-to-linq-queries.md)
- [LINQ in Visual Basic](../../visual-basic/programming-guide/language-features/linq/index.md)
- [Language-Integrated Query (LINQ) (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/index.md)
- [Getting Started with LINQ in Visual Basic](../../visual-basic/programming-guide/concepts/linq/getting-started-with-linq.md)
- [Writing Your First LINQ Query (Visual Basic)](../../visual-basic/programming-guide/concepts/linq/writing-your-first-linq-query.md)
Loading