What's the difference between xsd:include
and xsd:import
? When would you use one instead of the other, and when might it not matter?
xsd:include和xsd:import之间的区别是什么?你什么时候会用一个而不是另一个,什么时候不重要?
7 个解决方案
#1
167
The fundamental difference between include
and import
is that you must use import
to refer to declarations or definitions that are in a different target namespace and you must use include
to refer to declarations or definitions that are (or will be) in the same target namespace.
include和import之间的根本区别在于,您必须使用import来引用位于不同目标名称空间中的声明或定义,并且必须使用include来引用位于相同目标名称空间中的声明或定义。
Source: https://web.archive.org/web/20070804031046/http://xsd.stylusstudio.com/2002Jun/post08016.htm
来源:https://web.archive.org/web/20070804031046/http / /xsd.stylusstudio.com/2002Jun/post08016.htm
#2
41
Use xsd:include to bring in an XSD from the same or no namespace.
使用xsd:include从相同或没有命名空间引入xsd。
Use xsd:import to bring in an XSD from a different namespace.
使用xsd:import从不同的名称空间引入xsd。
#3
16
Another difference is that <import>
allows importing by referring to another namespace. <include>
only allows importing by referring to a URI of intended include schema. That is definitely another difference than inter-intra namespace importing.
另一个区别是
For example, the xml schema validator may already know the locations of all schemas by namespace already. Especially considering that referring to XML namespaces by URI may be problematic on different systems where classpath:// means nothing, or where http:// isn't allowed, or where some URI doesn't point to the same thing as it does on another system.
例如,xml模式验证器可能已经通过名称空间知道所有模式的位置。特别是考虑到使用URI引用XML名称空间在类路径://没有任何意义,或者不允许http://,或者某些URI不指向与其他系统相同的东西的不同系统中可能会有问题。
Code sample of valid and invalid imports and includes:
有效和无效导入的代码示例,包括:
Valid:
有效:
<xsd:import namespace="some/name/space"/>
<xsd:import schemaLocation="classpath://mine.xsd"/>
<xsd:include schemaLocation="classpath://mine.xsd"/>
Invalid:
无效:
<xsd:include namespace="some/name/space"/>
#4
8
I'm interested in this as well. The only explanation I've found is that xsd:include
is used for intra-namespace inclusions, while xsd:import
is for inter-namespace inclusion.
我也对这个感兴趣。我发现的惟一解释是xsd:include用于名称空间内部包含,而xsd:import用于名称空间内部包含。
#5
7
"include" Component - This component brings all declarations and definitions of an external schema document into the current schema. The external schema document must have the same target namespace as the current schema. "include" components are usually used to build a new schema by extending existing schema documents.
“包含”组件——该组件将外部模式文档的所有声明和定义带入当前模式。外部模式文档必须与当前模式具有相同的目标命名空间。“包含”组件通常通过扩展现有的模式文档来构建新的模式。
"import" Component - This component offers the same functions as the "include" component except that the included schema document has a different target namespace. "import" components are usually used to build a new schema by borrowing element declarations from existing schema documents from other namespaces.
“导入”组件——此组件提供与“include”组件相同的功能,只是包含的模式文档有不同的目标名称空间。“导入”组件通常用于通过从其他名称空间中的现有模式文档中借用元素声明来构建新的模式。
#6
-1
Direct quote from MSDN: <xsd:import> Element, Remarks section
直接引用MSDN:
The difference between the include element and the import element is that import element allows references to schema components from schema documents with different target namespaces and the include element adds the schema components from other schema documents that have the same target namespace (or no specified target namespace) to the containing schema. In short, the import element allows you to use schema components from any schema; the include element allows you to add all the components of an included schema to the containing schema.
包括元素和导入元素之间的区别是,导入元素允许引用模式组件与不同的目标名称空间的模式文档,包括元素添加模式组件从其他相同的目标名称空间的模式文档(或没有指定目标命名空间)包含模式。简而言之,导入元素允许您使用来自任何模式的模式组件;include元素允许您将包含的模式的所有组件添加到包含的模式中。
#7
-2
Use xsd:include brings all declarations and definitions of an external schema document into the current schema.
使用xsd:include将外部模式文档的所有声明和定义带到当前模式中。
Use xsd:import to bring in an XSD from a different namespace and used to build a new schema by extending existing schema documents..
使用xsd:import从不同的名称空间引入xsd,并通过扩展现有的模式文档来构建新的模式。
#1
167
The fundamental difference between include
and import
is that you must use import
to refer to declarations or definitions that are in a different target namespace and you must use include
to refer to declarations or definitions that are (or will be) in the same target namespace.
include和import之间的根本区别在于,您必须使用import来引用位于不同目标名称空间中的声明或定义,并且必须使用include来引用位于相同目标名称空间中的声明或定义。
Source: https://web.archive.org/web/20070804031046/http://xsd.stylusstudio.com/2002Jun/post08016.htm
来源:https://web.archive.org/web/20070804031046/http / /xsd.stylusstudio.com/2002Jun/post08016.htm
#2
41
Use xsd:include to bring in an XSD from the same or no namespace.
使用xsd:include从相同或没有命名空间引入xsd。
Use xsd:import to bring in an XSD from a different namespace.
使用xsd:import从不同的名称空间引入xsd。
#3
16
Another difference is that <import>
allows importing by referring to another namespace. <include>
only allows importing by referring to a URI of intended include schema. That is definitely another difference than inter-intra namespace importing.
另一个区别是
For example, the xml schema validator may already know the locations of all schemas by namespace already. Especially considering that referring to XML namespaces by URI may be problematic on different systems where classpath:// means nothing, or where http:// isn't allowed, or where some URI doesn't point to the same thing as it does on another system.
例如,xml模式验证器可能已经通过名称空间知道所有模式的位置。特别是考虑到使用URI引用XML名称空间在类路径://没有任何意义,或者不允许http://,或者某些URI不指向与其他系统相同的东西的不同系统中可能会有问题。
Code sample of valid and invalid imports and includes:
有效和无效导入的代码示例,包括:
Valid:
有效:
<xsd:import namespace="some/name/space"/>
<xsd:import schemaLocation="classpath://mine.xsd"/>
<xsd:include schemaLocation="classpath://mine.xsd"/>
Invalid:
无效:
<xsd:include namespace="some/name/space"/>
#4
8
I'm interested in this as well. The only explanation I've found is that xsd:include
is used for intra-namespace inclusions, while xsd:import
is for inter-namespace inclusion.
我也对这个感兴趣。我发现的惟一解释是xsd:include用于名称空间内部包含,而xsd:import用于名称空间内部包含。
#5
7
"include" Component - This component brings all declarations and definitions of an external schema document into the current schema. The external schema document must have the same target namespace as the current schema. "include" components are usually used to build a new schema by extending existing schema documents.
“包含”组件——该组件将外部模式文档的所有声明和定义带入当前模式。外部模式文档必须与当前模式具有相同的目标命名空间。“包含”组件通常通过扩展现有的模式文档来构建新的模式。
"import" Component - This component offers the same functions as the "include" component except that the included schema document has a different target namespace. "import" components are usually used to build a new schema by borrowing element declarations from existing schema documents from other namespaces.
“导入”组件——此组件提供与“include”组件相同的功能,只是包含的模式文档有不同的目标名称空间。“导入”组件通常用于通过从其他名称空间中的现有模式文档中借用元素声明来构建新的模式。
#6
-1
Direct quote from MSDN: <xsd:import> Element, Remarks section
直接引用MSDN:
The difference between the include element and the import element is that import element allows references to schema components from schema documents with different target namespaces and the include element adds the schema components from other schema documents that have the same target namespace (or no specified target namespace) to the containing schema. In short, the import element allows you to use schema components from any schema; the include element allows you to add all the components of an included schema to the containing schema.
包括元素和导入元素之间的区别是,导入元素允许引用模式组件与不同的目标名称空间的模式文档,包括元素添加模式组件从其他相同的目标名称空间的模式文档(或没有指定目标命名空间)包含模式。简而言之,导入元素允许您使用来自任何模式的模式组件;include元素允许您将包含的模式的所有组件添加到包含的模式中。
#7
-2
Use xsd:include brings all declarations and definitions of an external schema document into the current schema.
使用xsd:include将外部模式文档的所有声明和定义带到当前模式中。
Use xsd:import to bring in an XSD from a different namespace and used to build a new schema by extending existing schema documents..
使用xsd:import从不同的名称空间引入xsd,并通过扩展现有的模式文档来构建新的模式。