Condividi tramite


Procedura: dichiarare e utilizzare prefissi dello spazio dei nomi XML

Aggiornamento: novembre 2007

In questo esempio viene illustrato come importare il prefisso dello spazio dei nomi XML ns e utilizzarlo in un valore letterale XML e nelle proprietà axis XML.

Esempio

' 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

Compilazione del codice

L'esempio presenta i seguenti requisiti:

Vedere anche

Riferimenti

Istruzione Imports (spazio dei nomi XML)

Proprietà axis attributo XML

Proprietà Value XML

XElement.Attributes

Altre risorse

Accesso a XML in Visual Basic

XML in Visual Basic