如何:控制命名空间前缀 (Visual Basic) (LINQ to XML)

更新:November 2007

本主题说明如何控制命名空间前缀。

示例

说明

本示例声明两个命名空间。 它指定 https://www.adventure-works.com 命名空间具有 aw 前缀,www.fourthcoffee.com 命名空间具有 fc 前缀。

代码

Imports <xmlns:aw="https://www.adventure-works.com">
Imports <xmlns:fc="www.fourthcoffee.com">

Module Module1

    Sub Main()
        Dim root As XElement = _
            <aw:Root>
                <fc:Child>
                    <aw:DifferentChild>other content</aw:DifferentChild>
                </fc:Child>
                <aw:Child2>c2 content</aw:Child2>
                <fc:Child3>c3 content</fc:Child3>
            </aw:Root>
        Console.WriteLine(root)
    End Sub

End Module

注释

本示例生成以下输出:

<aw:Root xmlns:fc="www.fourthcoffee.com" xmlns:aw="https://www.adventure-works.com">
  <fc:Child>
    <aw:DifferentChild>other content</aw:DifferentChild>
  </fc:Child>
  <aw:Child2>c2 content</aw:Child2>
  <fc:Child3>c3 content</fc:Child3>
</aw:Root>

请参见

概念

Visual Basic 中的命名空间 (LINQ to XML)