Como: Acessar Elementos Descendant XML (Visual Basic)

This example shows how to use a descendant axis property to access all XML elements that have a specified name and that are contained under an XML element. In particular, it uses the Value property to get the value of the first element in the collection that the name descendant axis property returns. The name descendant axis property gets all elements named name that are contained in the contacts object. This example also uses the phone descendant axis property to access all descendants named phone that are contained in the contacts object.

Exemplo

Dim contacts As XElement = 
<contacts>
    <contact>
        <name>Patrick Hines</name>
        <phone type="home">206-555-0144</phone>
        <phone type="work">425-555-0145</phone>
    </contact>
</contacts>

Console.WriteLine("Name: " & contacts...<name>.Value)

Dim phoneTypes As XElement = 
  <phoneTypes>
      <%= From phone In contacts...<phone> 
          Select <type><%= phone.@type %></type> 
      %>
  </phoneTypes>

Console.WriteLine(phoneTypes)

Compilando o código

This example requires:

Consulte também

Referência

Propriedade de eixo descendente XML (Visual Basic)

Propriedade de valor XML (Visual Basic)

XContainer.Descendants

Outros recursos

Acessando XML no Visual Basic

XML no Visual Basic