共用方式為


如何:宣告和使用 XML 命名空間前置字元 (Visual Basic)

這個範例顯示如何匯入 XML 命名空間前置字元 ns,並在 XML 常值 (Literal) 和 XML 軸屬性中使用此前置字元。

範例

' 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

編譯程式碼

這個範例需要:

請參閱

參考

Imports 陳述式 (XML 命名空間)

XML 屬性軸屬性 (Visual Basic)

XML Value 屬性 (Visual Basic)

XElement.Attributes

其他資源

在 Visual Basic 中存取 XML

Visual Basic 中的 XML