Validation XML Schema 1.0-限定与非限定:有效实例中具体发生了哪些变化?
假设我有一个有效的XML实例文件(“1”),它只包含其模式(模式“a”)的Validation XML Schema 1.0-限定与非限定:有效实例中具体发生了哪些变化?,validation,xsd,xml-namespaces,Validation,Xsd,Xml Namespaces,假设我有一个有效的XML实例文件(“1”),它只包含其模式(模式“a”)的targetNamespace中的元素。根据此架构,该实例是有效的。实例1在其(1)根节点上,而在其他任何地方,都有正确的架构命名空间声明 现在,我使用相同的实例1,并尝试根据模式“B”验证它 B与A相同,只是我将elementFormDefault=“unqualified”更改为elementFormDefault=“qualified” 我看到1无法验证B。为什么?我需要在1(生成实例“2”)中更改什么才能使其对B再
targetNamespace
中的元素。根据此架构,该实例是有效的。实例1在其(1)根节点上,而在其他任何地方,都有正确的架构命名空间声明
现在,我使用相同的实例1,并尝试根据模式“B”验证它
B与A相同,只是我将elementFormDefault=“unqualified”
更改为elementFormDefault=“qualified”
我看到1无法验证B。为什么?我需要在1(生成实例“2”)中更改什么才能使其对B再次有效
XML模式的“限定”风格是否仅适用于每个元素上都有显式命名空间前缀的实例
示例模式:所有模式都基于最小的XML结构,用于通信一些数据结构,如
file/record/info1
。不幸的是,这些行为似乎与我的现实世界的例子(太大了,无法在这里发布)有所不同
A:非限定模式
<?xml version="1.0" encoding="UTF-8"?>
<!-- The UNqualified version -->
<xs:schema elementFormDefault="unqualified" targetNamespace="http://example.com/xsd-prefixes-test"
xmlns:test="http://example.com/xsd-prefixes-test" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="file">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="test:record" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="record">
<xs:complexType>
<xs:sequence>
<xs:element ref="test:info1" />
<xs:element ref="test:info2" />
</xs:sequence>
<xs:attribute name="id" type="xs:integer" use="required" />
<xs:attribute name="status" type="xs:NCName" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="info1">
<xs:complexType />
</xs:element>
<xs:element name="info2">
<xs:complexType />
</xs:element>
</xs:schema>
B:限定模式
<?xml version="1.0" encoding="UTF-8"?>
<!-- The QUALIFIED version -->
<xs:schema elementFormDefault="qualified" targetNamespace="http://example.com/xsd-prefixes-test"
xmlns:test="http://example.com/xsd-prefixes-test" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="file">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="test:record" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="record">
<xs:complexType>
<xs:sequence>
<xs:element ref="test:info1" />
<xs:element ref="test:info2" />
</xs:sequence>
<xs:attribute name="id" type="xs:integer" use="required" />
<xs:attribute name="status" type="xs:NCName" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="info1">
<xs:complexType />
</xs:element>
<xs:element name="info2">
<xs:complexType />
</xs:element>
</xs:schema>
架构实例示例: 实例1-所有元素上targetNamespace的前缀;针对两个架构进行验证
实例2:-任何地方都没有名称空间前缀,但仍然针对A和B进行验证
<?xml version="1.0" encoding="UTF-8"?>
<!-- NO prefixes anywhere -->
<file xmlns="http://example.com/xsd-prefixes-test" xmlns:test="http://example.com/xsd-prefixes-test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com/xsd-prefixes-test xsd-prefixes-test_qualified.xsd">
<!-- validates against BOTH xsd-prefixes-test_UNqualified.xsd AND xsd-prefixes-test_qualified.xsd -->
<record id="1" status="ok">
<info1 />
<info2 />
<!-- etc... -->
</record>
<record id="1" status="ok">
<info1 />
<info2 />
<!-- etc... -->
</record>
<record id="1" status="duplicate_deprecated">
<info1 />
<info2 />
<!-- etc... -->
</record>
</file>
实例3-不针对A或B进行验证-为什么不
<?xml version="1.0" encoding="UTF-8"?>
<!-- NO prefixes anywhere -->
<test:file xmlns:test="http://example.com/xsd-prefixes-test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com/xsd-prefixes-test xsd-prefixes-test_qualified.xsd">
<!-- validates against NEITHER xsd-prefixes-test_UNqualified.xsd NOR xsd-prefixes-test_qualified.xsd -->
<record id="1" status="ok">
<info1 />
<info2 />
<!-- etc... -->
</record>
<record id="1" status="ok">
<info1 />
<info2 />
<!-- etc... -->
</record>
<record id="1" status="duplicate_deprecated">
<info1 />
<info2 />
<!-- etc... -->
</record>
</test:file>
错误消息(与模式A和B相同):
- 实例3-cvc复杂类型。2.4.a:发现以元素“record”开头的无效内容。应为“{”“:record}”之一
当与“相反”风格的模式(带有前缀的实例与带有不合格前缀的模式)一起使用时,我在1和2的模式下看到了这个错误或非常类似的错误 相反,我看到样式3的实例确实根据限定类型模式进行验证
- 是否依赖于所使用的语言/解析器/验证引擎
elementFormDefault=“unqualified”
更改为elementFormDefault=“qualified”
时,实例中必须更改什么才能保持实例的有效性?好的,我只是将我的xsd的原始“unqualified”版本与更新的“qualified”版本进行了比较这绝对是使用oxygen XML编辑器在双向差异中发现的唯一更改。为什么对某些实例来说这是一个突破性的更改?
<?xml version="1.0" encoding="UTF-8"?>
<!-- NO prefixes anywhere -->
<test:file xmlns:test="http://example.com/xsd-prefixes-test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com/xsd-prefixes-test xsd-prefixes-test_qualified.xsd">
<!-- validates against NEITHER xsd-prefixes-test_UNqualified.xsd NOR xsd-prefixes-test_qualified.xsd -->
<record id="1" status="ok">
<info1 />
<info2 />
<!-- etc... -->
</record>
<record id="1" status="ok">
<info1 />
<info2 />
<!-- etc... -->
</record>
<record id="1" status="duplicate_deprecated">
<info1 />
<info2 />
<!-- etc... -->
</record>
</test:file>