Поделиться через


Import Element Binding Support 

The .NET Framework provides partial binding support for the <import> element.

For the <import> element, the Xsd.exe tool ignores the schemaLocation attribute, expecting imported files instead as additional command-line arguments.

Explanation

The <import> element resembles the <include> element. Both elements appear as children of the root <schema> element; they must appear before any other children. Both pull in a separate <schema> definition, typically defined in another .xsd file. There is one key distinction, as follows:

  • <import>: Imports schema definitions and declarations within a separate namespace specified via the namespace attribute.

  • <include>: Includes additional schema definitions and declarations within the same namespace specified as the targetNamespace for the existing XML Schema definition.

The following is an example of the <import> element's usage:

<xsd:import namespace="http://example.org/attr" schemaLocation="http://example.org/definitions/attr.xsd" />

SchemaLocation Attribute

The schemaLocation attribute is intended to specify the location of the imported .xsd file. However, Xsd.exe ignores the schemaLocation attribute when it appears in the the <import> element. Instead, for Xsd.exe any imported files are specified as additional command-line arguments.

The generated source file gets the name of the last XSD file passed as an argument. Take as an example the following command-line invocation of Xsd.exe:

xsd importedAttribute.xsd attributeRef.xsd /classes /language:CS

The resulting source file is given the name attributeRef.cs.

Note

Xsd.exe does use the schemaLocation attribute when it appears in the <include> element. When generating source code from an XML Schema document, Xsd.exe recognizes an absolute file-system path for the value. See Include Element Binding Support.

Namespace Attribute

The namespace attribute is used to identify the imported target namespace, which must differ from the target namespace of the XSD document doing the importing (the one containing the <import> element).

When generating source code from an XML Schema document, Xsd.exe sets a Namespace property on the .NET Framework attribute that is applied to each type or field corresponding to an entity that is imported. Even when no extra namespaces are imported, Xsd.exe sets the Namespace property of the following two attributes to that of the original XSD document's target namespace:

An imported namespace can be specified via the Namespace property of certain XML-related attribute classes. The property appears as follows:

Possible Attributes Binding Support

id

The Xsd.exe utility ignores the id attribute, which is intended to provide a unique identifier.

namespace

See the preceding Namespace Attribute section.

schemaLocation

See the preceding SchemaLocation Attribute section.

Possible parent elements: <schema>

Possible child elements: <annotation>

See Also

Reference

XmlSchemaImport