xsd:include和xsd:import之间有什么区别?什么时候你会用一种而不是另一种,什么时候它可能无关紧要?
include和import之间的基本区别在于,必须使用import引用位于不同目标名称空间中的声明或定义,而必须使用include引用位于(或将位于)同一目标名称空间中的声明或定义。
来源:https://web.archive.org/web/20070804031046/http: / / xsd.stylusstudio.com/2002Jun/post08016.htm
直接引用MSDN: <xsd:import> Element,备注section
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.
另一个区别是<import>允许通过引用另一个名称空间进行导入。<include>只允许通过引用包含模式的URI来导入。这显然是与内部名称空间间导入的另一个区别。
例如,xml模式验证器可能已经通过名称空间知道了所有模式的位置。特别是考虑到在不同的系统上通过URI引用XML名称空间可能存在问题,其中classpath://没有任何意义,或者不允许使用http://,或者某些URI与在另一个系统上指向的东西不同。
有效和无效导入的代码示例,包括:
有效:
<xsd:import namespace="some/name/space"/>
<xsd:import schemaLocation="classpath://mine.xsd"/>
<xsd:include schemaLocation="classpath://mine.xsd"/>
无效:
<xsd:include namespace="some/name/space"/>
使用xsd:include将外部模式文档的所有声明和定义带入当前模式。
使用xsd:import从不同的名称空间引入一个xsd,用于通过扩展现有模式文档来构建一个新模式。
推荐文章
- XSD和WSDL之间的区别是什么?
- 如何将XML转换成PHP数组?
- XMLHttpRequest Origin null不允许Access-Control-Allow-Origin for file:/// to file:///(无服务器)
- LINQ读取XML
- 如何设置RecyclerView应用程序:layoutManager=""从XML?
- JavaScript中变量字符串的XML解析
- 具有多个条件的XPath
- 格式化XML字符串以打印友好的XML字符串
- malformedurlexception:没有协议
- 选择包含“foo”的属性的正确XPath是什么?
- 字符串资源新行/n不可能?
- Android: ScrollView vs NestedScrollView
- 如何把空格字符放入XML字符串名?
- 比较Java中2个XML文档的最佳方法
- 将XML字符串转换为对象