我试图写的以下XML示例XSD架构:这个XML应该是什么模式?
<?xml version="1.0" encoding="UTF-8"?>
<locs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="loc.xsd">
<loc required="true" comment="A comment">ABC</loc>
</locs>
我试图执行模式中的这些规则的规则:
- 根元素
locs
必须具有1种以上的元素的loc
loc
必须具有两个属性:required
是boolean
&comment
是string
,非零长度的,不共mposed完全空白的空间和/或标点符号loc
必须有一个字符串值,非零长度,而不是完全由空格和/或标点符号
我走了这么远用我loc.xsd
如下:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="locs">
<xs:complexType>
<xs:sequence>
<xs:element name="loc" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:complexContent>
<xs:extension base="xs:string">
<xs:attribute name="required" type="xs:boolean" use="required"/>
<xs:attribute name="comment" type="xs:string" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
有了这个,我能够执行规则1 & 2,但是,第三个规则未强制执行,因此类似下面的条目是有效的:
<loc required="false" comment="Another comment"/>
我错过了什么?我已经花了几个小时了!
您提出了一个很好的空白处!我改进了我的定义,以照顾它。 –