我在针对我定义的模式验证 xml 时遇到了一些问题。奇怪的是,只有当我使用默认命名空间时验证才会失败,xmlns="http://retis.sssup.it/duck-lab"
而如果我将其定义为xmlns:dl="http://retis.sssup.it/duck-lab"
.
当我使用空命名空间时,验证仅在具有以下消息的属性上失败:
cvc-complex-type.3.2.2: Attribute 'data_len' is not allowed to appear in element 'data'.
cvc-complex-type.4: Attribute 'data_len' must appear on element 'data'.
有效的 XML:
<dl:duck xmlns:dl="http://retis.sssup.it/duck-lab" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://retis.sssup.it/duck-lab ../duck.xsd ">
...
<dl:data dl:data_len="1" dl:data_name="name uint" dl:data_type="uint16" dl:endianess="big-endian"/>
无效的 XML:
<duck xmlns="http://retis.sssup.it/duck-lab" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://retis.sssup.it/duck-lab ../duck.xsd ">
...
<data data_len="1" data_name="name uint" data_type="uint16" endianess="big-endian"/>
- 编辑 -
鸭子.XSD
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://retis.sssup.it/duck-lab"
xmlns:dl="http://retis.sssup.it/duck-lab" elementFormDefault="qualified">
<include schemaLocation="datatypes.xsd"/>
<include schemaLocation="duck_message.xsd"/>
<complexType name="DuckDefinitionType" block="#all" final="#all">
<sequence>
<element type="dl:MessageType" name="message_description" form="qualified"/>
</sequence>
</complexType>
<element name="duck" type="dl:DuckDefinitionType" />
</schema>
数据类型.XSD
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://retis.sssup.it/duck-lab"
xmlns:dl="http://retis.sssup.it/duck-lab" elementFormDefault="qualified">
<attribute name="data_name" type="string"/>
<attribute name="data_len" type="nonNegativeInteger"/>
<attribute name="data_type" type="string"/>
<attribute name="endianess" type="string"/>
<element name="data">
<complexType>
<attribute ref="dl:data_name" use="required"/>
<attribute ref="dl:data_len" use="required"/>
<attribute ref="dl:data_type" use="required"/>
<attribute ref="dl:endianess" use="required"/>
</complexType>
</element>
</schema>
DUCK_MESSAGE.XSD
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://retis.sssup.it/duck-lab"
xmlns:dl="http://retis.sssup.it/duck-lab" elementFormDefault="qualified">
<include schemaLocation="datatypes.xsd"></include>
<complexType name="MessageType">
<sequence maxOccurs="unbounded">
<element ref="dl:data"></element>
</sequence>
</complexType>
</schema>
显然我可以绕过定义非空命名空间的问题,但我想了解什么是错的。
非常感谢。