Propriedade de eixo filho XML (Visual Basic)
Fornece acesso para os filhos de um dos seguintes: um XElementoobjeto, um XDocumentobjeto, uma coleção de XElement objetos, ou uma coleção de XDocument objetos.
object.<child>
Parts
Term |
Definition |
object |
Required. An XElement object, an XDocument object, a collection of XElement objects, or a collection of XDocument objects. |
.< |
Required. Denotes the start of a child axis property. |
child |
Required. Name of the child nodes to access, of the form [prefix:]name.
PartDescription
prefix Optional.XML namespace prefix for the child node.Must be a global XML namespace defined with an Imports statement.
name Required.Local child node name.See Nomes de elementos e atributos XML declarados (Visual Basic).
|
> |
Required. Denotes the end of a child axis property. |
Valor de retorno
Uma coleção de XElement objetos.
Comentários
You can use an XML child axis property to access child nodes by name from an XElement or XDocument object, or from a collection of XElement or XDocument objects. Use the XML Value property to access the value of the first child node in the returned collection. For more information, see Propriedade de valor XML (Visual Basic).
O Visual Basic compilador converte as propriedades de eixo filho chamadas para o Elements método.
XML Namespaces
The name in a child axis property can use only XML namespace prefixes declared globally with the Imports statement. It cannot use XML namespace prefixes declared locally within XML element literals. For more information, see Instrução Imports (Namespace XML).
Exemplo
The following example shows how to access the child nodes named phone from the contact object.
Dim contact As XElement =
<contact>
<name>Patrick Hines</name>
<phone type="home">206-555-0144</phone>
<phone type="work">425-555-0145</phone>
</contact>
Dim homePhone = From hp In contact.<phone>
Where contact.<phone>.@type = "home"
Select hp
Console.WriteLine("Home Phone = {0}", homePhone(0).Value)
This code displays the following text:
Home Phone = 206-555-0144
The following example shows how to access the child nodes named phone from the collection returned by the contact child axis property of the contacts object.
Dim contacts As XElement =
<contacts>
<contact>
<name>Patrick Hines</name>
<phone type="home">206-555-0144</phone>
</contact>
<contact>
<name>Lance Tucker</name>
<phone type="work">425-555-0145</phone>
</contact>
</contacts>
Dim homePhone = From contact In contacts.<contact>
Where contact.<phone>.@type = "home"
Select contact.<phone>
Console.WriteLine("Home Phone = {0}", homePhone(0).Value)
This code displays the following text:
Home Phone = 206-555-0144
The following example declares ns as an XML namespace prefix. It then uses the prefix of the namespace to create an XML literal and access the first child node with the qualified name ns:name.
Imports <xmlns:ns = "http://SomeNamespace">
Class TestClass4
Shared Sub TestPrefix()
Dim contact = <ns:contact>
<ns:name>Patrick Hines</ns:name>
</ns:contact>
Console.WriteLine(contact.<ns:name>.Value)
End Sub
End Class
This code displays the following text:
Patrick Hines
Consulte também
Referência
Conceitos
Nomes de elementos e atributos XML declarados (Visual Basic)