xml xsd:include 和 xsd:import 之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2357943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between xsd:include and xsd:import?
提问by Pops
What's the difference between xsd:includeand xsd:import? When would you use one instead of the other, and when might it not matter?
xsd:include和 和有xsd:import什么区别?你什么时候会使用一个而不是另一个,什么时候可能无关紧要?
回答by Sergiy Belozorov
The fundamental difference between includeand importis that you must use importto refer to declarations or definitions that are in a differenttarget namespace and you must use includeto refer to declarations or definitions that are (or will be) in the sametarget 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
回答by kjhughes
Use xsd:includeto bring in an XSD from the sameor no namespace.
使用xsd:include从相同或没有命名空间中引入 XSD 。
Use xsd:importto bring in an XSD from a differentnamespace.
使用xsd:import从不同的命名空间引入 XSD 。
回答by Zombies
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.
另一个区别是<import>允许通过引用另一个命名空间进行导入。<include>仅允许通过引用预期包含模式的 URI 进行导入。这绝对是与内部命名空间导入不同的另一个区别。
For example, the xml schema validator may already know the locations of all schemas by namespacealready. 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 命名空间在不同的系统上可能会出现问题,其中 classpath:// 没有任何意义,或者不允许 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"/>
回答by Matt Luongo
I'm interested in this as well. The only explanation I've found is that xsd:includeis used for intra-namespace inclusions, while xsd:importis for inter-namespace inclusion.
我也对这个感兴趣。我发现的唯一解释xsd:include是用于名称空间内包含,而xsd:import用于名称空间间包含。
回答by Mrinmoy Sarkar
Direct quote from MSDN: <xsd:import> Element, Remarks section
直接引用自MSDN:<xsd:import> 元素,备注部分
The difference between the includeelement and the importelement is that importelement allows references to schema components from schema documents with different target namespaces and the includeelement 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 importelement allows you to use schema components from any schema; the includeelement allows you to add all the components of an included schema to the containing schema.
include元素和import元素之间的区别在于import元素允许从具有不同目标命名空间的架构文档中引用架构组件,而include元素从具有相同目标命名空间(或没有指定目标命名空间)的其他架构文档中添加架构组件) 到包含架构。简而言之,import元素允许您使用任何架构中的架构组件;在包括元素,可以包含的架构的所有组件添加到包含架构。
回答by Shailej Shimpi
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,并用于通过扩展现有架构文档来构建新架构。

