给定一个顶级xsd导入第二个级别,然后导入第三个级别,是否可以使用第一个级别的第三个级别?或者第一个必须直接导入第三个?从xsd使用类型从导入导入
回答
如果type
是你在说些什么的话..这<xs:Include>
不<xs:Import>
..
答案是:分析器需要连接所有的XSD一起照顾
见下面的例子:
<?xml version="1.0" encoding="utf-8"?>
<root>
<child>trial</child>
<child2>trial2</child2>
<trunk>
<branch>1</branch>
<branch>2</branch>
</trunk>
<specialchild>test</specialchild>
</root>
对于上述XML我将设计的XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="include multiple XSDs2.xsd"/>
<xs:element name="root" type ="root"/>
<xs:complexType name="root">
<xs:sequence>
<xs:element name="child" type="xs:string" />
<xs:element name="child2" type="xs:string" />
<xs:element name="trunk" type="trunk"/>
<xs:element name="specialchild" type="specialchild"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
其中类型中继线在import multiple XSDs2.xsd
文件中定义和链接通过使用<xs:include>
..(其驻留在相同的文件夹)。并且代码看起来是这样的:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="include multiple XSDs3.xsd"/>
<xs:complexType name="trunk">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="branch" type="branch" />
</xs:sequence>
</xs:complexType>
</xs:schema>
和类型分支是一个简单类型include multiple XSDs3.xsd
文件定义,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="branch">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:simpleType name="specialchild">
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:schema>
* 现在棘手的问题是:specialchild
在XSD_1
宣布作为地方在XSD_3
中定义,这两个XSD通过XSD_2
连接。 您可以观察到默认情况下解析器负责连接所有XSD并将它们全部视为一个! *
希望这能解决您的问题!
好问题! 从阅读规范,我不能告诉。它没有明确地解决传递导入的问题。
在底漆(部分0),他们只谈论进口的约一层:http://www.w3.org/TR/xmlschema-0/#import
在结构(部分1),它也只定义直接导入http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#composition-schemaImport既然谈到“解决这样的手段外部组件“(我认为这意味着命名空间),也许有必要假定一种明确的方式来处理导入的模式是必要的 - 换句话说,每个导入模式都需要一个明确的命名空间。
谷歌搜索显示,其他人也被这个问题困惑:
什么是最关心的那些帖子是不同的XSD的处理器有不同行为 - 这表明处理器的作者也感到困惑。
虽然自那些帖子(2002,2005)以来可能已经发生了变化,但最明智的做法似乎是避免这个问题,并且只使用直接导入,因为这将适用于所有处理器。
正如我所说:很好的问题。
下面是测试,来检查XSD处理器(当然,这并不能保证它会为别人工作,否则使用一些其他的XSD处理器...)。我发现我最喜欢的一个(xmllint)不允许允许传递导入。
测试是三个模式:a.xsd进口b.xsd这反过来进口c.xsd;和在定义的类型c.xsd从a.xsd引用:
<!-- a.xsd -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.c.com" targetNamespace="http://www.a.com">
<xsd:import namespace="http://www.b.com" schemaLocation="b.xsd"/>
<!-- UNCOMMENT FOR DIRECT IMPORT
<xsd:import namespace="http://www.c.com" schemaLocation="c.xsd"/>
-->
<xsd:element name="eg" type="c:TypeC"/>
</xsd:schema>
<!-- b.xsd -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.c.com" schemaLocation="c.xsd"/>
</xsd:schema>
<!-- c.xsd -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.c.com">
<xsd:simpleType name="TypeC">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:schema>
<!-- a.xml -->
<eg xmlns="http://www.a.com">hello world</eg>
$ xmllint --schema a.xsd a.xml --noout
a.xsd:6: element element: Schemas parser error : Element
'{http://www.w3.org/2001/XMLSchema}element', attribute 'type': References from
this schema to components in the namespace 'http://www.c.com' are not allowed,
since not indicated by an import statement.
WXS schema a.xsd failed to compile
的错误信息是:References from this schema to components in the namespace 'http://www.c.com' are not allowed, since not indicated by an import statement.
,表明xmllint的开发者至少是相当肯定进口不可传递。
- 1. 从文件中导入XSD
- 2. 从xsd与mutlitlevel导入生成java类
- 3. 从一个xsd导入只有几个类型到另一个
- 4. 为什么我可以从xsd模式导入此类型?
- 5. 从导入的XSD扩展复杂类型
- 6. 从xsd文件导出类型列表
- 7. 从prefix.pch导入类
- 8. Proc导入从CSV中导入错误的数据类型
- 9. 从python中导入导入导入
- 10. `从'...''导入*作为什么类型?
- 11. 模型类从打包库中导入?
- 12. django从模型导入类的错误
- 13. XSD导入问题
- 14. 从导入的类中引用导入的类
- 15. LoopBack:从MySql导入模型
- 16. 从GitHub导入maven原型
- 17. 导轨从csv导入模型
- 18. SQL Server从.tsv或.txt导入错误(使用导入向导)
- 19. 导入类从子目录
- 20. 如何从ndb.Model导入类?
- 21. python从python包导入类
- 22. 从Xtext导入Java类dsl
- 23. 从Python导入类嘲笑
- 24. 如何从dll导入类?
- 25. 从文件夹导入类
- 26. 从子类中导入implicits
- 27. 从不同的项目导入xsd,生成java类
- 28. 使用从sys导入输入argv
- 29. XSD:导入复杂类型不起作用
- 30. 导入从gi.repository