You can use the Imports statement to define global XML namespaces that you can use with XML literals and XML axis properties, or as parameters passed to the GetXmlNamespace operator. (For information about using the Imports statement to import an alias that can be used where type names are used in your code, see Imports Statement (.NET Namespace and Type).) The syntax for declaring an XML namespace by using the Imports statement is identical to the syntax used in XML. Therefore, you can copy a namespace declaration from an XML file and use it in an Imports statement.
XML namespace prefixes are useful when you want to repeatedly create XML elements that are from the same namespace. The XML namespace prefix declared with the Imports statement is global in the sense that it is available to all code in the file. You can use it when you create XML element literals and when you access XML axis properties. For more information, see XML Element Literal and XML Axis Properties.
If you define a global XML namespace without a namespace prefix (for example, Imports <xmlns="http://SomeNameSpace>"), that namespace is considered the default XML namespace. The default XML namespace is used for any XML element literals or XML attribute axis properties that do not explicitly specify a namespace. The default namespace is also used if the specified namespace is the empty namespace (that is, xmlns=""). The default XML namespace does not apply to XML attributes in XML literals or to XML attribute axis properties that do not have a namespace.
XML namespaces that are defined in an XML literal, which are called local XML namespaces, take precedence over XML namespaces that are defined by the Imports statement as global. XML namespaces that are defined by the Imports statement take precedence over XML namespaces imported for a Visual Basic project. If an XML literal defines an XML namespace, that local namespace does not apply to embedded expressions.
Global XML namespaces follow the same scoping and definition rules as .NET Framework namespaces. As a result, you can include an Imports statement to define a global XML namespace anywhere you can import a .NET Framework namespace. This includes both code files and project-level imported namespaces. For information about project-level imported namespaces, see References Page, Project Designer (Visual Basic).
Each source file can contain any number of Imports statements. These must follow option declarations, such as the Option Strict statement, and they must precede programming element declarations, such as Module or Class statements.