Compartilhar via


How to: Control Namespace Prefixes (Visual Basic) (LINQ to XML)

This topic describes how you can control namespace prefixes.

Example

Description

This example declares two namespaces. It specifies that the https://www.adventure-works.com namespace has the prefix aw, and that the www.fourthcoffee.com namespace has the prefix of fc.

Code

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

Comments

This example produces the following output:

<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>

See Also

Concepts

Namespaces in Visual Basic (LINQ to XML)