Freigeben über


Gewusst wie: Deklarieren und Verwenden von XML-Namespacepräfixen (Visual Basic)

In diesem Beispiel wird gezeigt, wie das XML-Namespacepräfix ns importiert wird und als XML-Literal sowie als XML-Achseneigenschaften verwendet wird.

Beispiel

' Place Imports statements at the top of your program.  
Imports <xmlns:ns="http://SomeNamespace">

Module Sample1

    Sub SampleTransform()

        ' Create test by using a global XML namespace prefix. 

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

        Dim phoneTypes = 
          <phoneTypes>
              <%= From phone In contact.<ns:phone> 
                  Select <type><%= phone.@ns:type %></type> 
              %>
          </phoneTypes>

        Console.WriteLine(phoneTypes)
    End Sub

End Module

Kompilieren des Codes

Dieses Beispiel setzt Folgendes voraus:

Siehe auch

Referenz

Imports-Anweisung (XML-Namespace)

XML-Attributachseneigenschaft (Visual Basic)

XML-Value-Eigenschaft (Visual Basic)

XElement.Attributes

Weitere Ressourcen

Zugreifen auf XML in Visual Basic

XML in Visual Basic