Query elements by attribute value : XAttribute « XML LINQ « VB.Net






Query elements by attribute value

   

Imports System
Imports System.Reflection
Imports System.Xml

Module Module1

    Sub Main()
        Dim xml As XDocument = XDocument.Load("People.xml")

        Dim query = From p In xml.Elements("people").Elements("person") _
            Where p.Element("id").Value = 1 _
            Select p

        For Each record In query
            Console.WriteLine("Person: {0} {1}", _
               record.Element("firstname").Value, _
               record.Element("lastname").Value)
        Next

    End Sub
End Module

   
    
    
  








Related examples in the same category

1.Build an XML element in memory
2.FirstName tag's parent has attributes
3.Using Linq Xml to query attribute
4.The element axis property (<>) and the attribute axis property (@) are used to access the id attribute.
5.XAttribute Class represents an XML attribute.
6.Create XAttribute class from the specified name and value.
7.XAttribute.IsNamespaceDeclaration
8.XAttribute.Name Property gets the expanded name of this attribute.
9.XAttribute.NextAttribute Property gets the next attribute of the parent element.
10.XAttribute.NodeType Property gets the node type for this node.
11.XAttribute.PreviousAttribute Property gets the previous attribute of the parent element.
12.XAttribute.Remove removes this attribute from its parent element.
13.XAttribute.SetValue sets the value of this attribute.
14.Converts the current XAttribute object to a string representation.
15.XAttribute.Value Property gets or sets the value of this attribute.
16.XAttribute object content
17.XAttribute object array content
18.XElement.Attribute returns the XAttribute of this XElement that has the specified XName.
19.ReplaceAll with an XAttribute object
20.ReplaceAll with an array of XAttribute objects
21.Add XAttribute with namespace to XElement
22.XAttribute with namespace