Literal text for the element name, of the form [ePrefix:]eName, where:

Part

Description

ePrefix

Optional. XML namespace prefix for the element. Must be a global XML namespace that is defined with an Imports statement in the file or at the project level, or a local XML namespace that is defined in this element or a parent element.

Embedded expression of the form <%= eNameExp%>. The type of eNameExp must be String or a type that is implicitly convertible to XName.

Embedded expression of the form <%=nameExp%>. The type of nameExp must be String or a type implicitly convertible to XName. An embedded expression is not allowed in a closing tag of an element.

attributeList

Optional. List of attributes declared in the literal.

attribute [ attribute ... ]

Each attribute has one of the following syntaxes:

Attribute assignment, of the form [aPrefix:]aName=aValue, where:

Part

Description

aPrefix

Optional. XML namespace prefix for the attribute. Must be a global XML namespace that is defined with an Imports statement, or a local XML namespace that is defined in this element or a parent element.

The Visual Basic compiler converts the XML element literal into calls to the XElement constructor and, if it is required, the XAttribute constructor.

XML Namespaces

XML namespace prefixes are useful when you have to create XML literals with elements from the same namespace many times in code. You can use global XML namespace prefixes, which you define by using the Imports statement, or local prefixes, which you define by using the xmlns:xmlPrefix="xmlNamespace" attribute syntax. For more information, see Imports Statement (XML Namespace).

In accordance with the scoping rules for XML namespaces, local prefixes take precedence over global prefixes. However, if an XML literal defines an XML namespace, that namespace is not available to expressions that appear in an embedded expression. The embedded expression can access only the global XML namespace.

The Visual Basic compiler converts each global XML namespace that is used by an XML literal into a one local namespace definition in the generated code. Global XML namespaces that are not used do not appear in the generated code.

Notice that the compiler converted the prefix of the global XML namespace into a prefix definition for the XML namespace. The <ns:middle> element redefines the XML namespace prefix for the <ns:inner1> element. However, the <ns:inner2> element uses the namespace defined by the Imports statement.