我需要创建一个 XSD 1.0来验证 XML 文件。
验证将使用 python 中的 lxml.etree ,此工具仅支持XML Schema 1.0(lxml with schema 1.1)
我需要使用的结构是:
item
| owners*
| config+
| | config_id
| | tests*
| | picked?
| | capability*
| | | name
| | | value
用过的符号是:
*
元素可以出现零次或多次。+
元素可以出现一次或多次。?
该元素是可选的。配置标记中的元素可以是任何顺序,这意味着我无法使用<sequence>
指标。 <all>
指标为我提供了随机顺序,但在这种情况下,maxOccurs
为1. <choice>
指标maxOccurs="unbounded"
将为我提供随机顺序和多个元素,但元素没有底限。
我的XSD文件类似于:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--Schema version: 1.0, date: 29-02-2016-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- definition of complex types -->
<xs:complexType name="capability_type">
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="value" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="config_type">
<xs:all>
<xs:element name="config_id" type="xs:string" />
<xs:element name="tests" type="xs:string" minOccurs="0"
maxOccurs="unbounded" />
<xs:element name="picked" type="xs:string" minOccurs="0" />
<xs:element name="capability" type="capability_type"
minOccurs="0" maxOccurs="unbounded" />
</xs:all>
</xs:complexType>
<xs:complexType name="item_type">
<xs:sequence>
<xs:element name="owners" type="xs:string" minOccurs="0"
maxOccurs="unbounded" />
<xs:element name="config" type="config_type" minOccurs="1"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<!-- definition of schema -->
<xs:element name="item" type="item_type" />
</xs:schema>
使用此架构我收到错误:
元素元素:模式解析器错误:元素 &#39; {http://www.w3.org/2001/XMLSchema}元素&#39;:无效的值 maxOccurs(必须为0或1)。
我的问题还有其他选择吗?
答案 0 :(得分:1)
是的,还有其他选择:
SKIP (for line 1 ... removed 45 Lines for better readablity
SKIP to line 47)
4.163186002791e+04 3.578830331359e+04 3.076496349687e+04 2.644671278966e+04 2.273458304119e+04
1.954349752908e+04 1.680032112209e+04 1.444218412726e+04 1.241504140604e+04 1.067243373686e+04
9.174423035938e+03 7.886677033340e+03 6.779682426302e+03 5.828068476394e+03 5.010025548360e+03
1.737988920100e+03 1.284332855871e+03 1.104060538508e+03 8.158747205330e+02 7.013564117662e+02
6.029121922103e+02 5.182858606802e+02 4.455379022877e+02 2.433020871700e+02 2.091515701348e+02
1.797945089525e+02 1.545580816278e+02 1.328639052196e+02 9.818329499070e+01 7.255514128762e+01
5.361653963401e+01 4.609078195788e+01 3.962135930423e+01 3.406000172766e+01 2.927925083995e+01
2.516953864546e+01 2.163667639887e+01 1.859969593339e+01 1.598899398582e+01 1.374473698894e+01
1.181548977143e+01 1.015703673713e+01 8.731368506527e+00 7.505810795983e+00 6.452275569743e+00
5.546617302183e+00 4.768079596776e+00 4.098819479081e+00 3.523498461194e+00 3.028931005477e+00
2.603782330822e+00 2.238308635635e+00 1.924133783786e+00 1.654057335509e+00 1.421889523591e+00
1.222309392724e+00 1.050742850800e+00 9.032578372386e-01 7.764742057598e-01 6.674862562538e-01
5.737961402745e-01 4.932566139141e-01 3.133421372728e-01 2.315524554696e-01 1.990511474577e-01
1.711118080085e-01 1.470941072881e-01 1.264475938317e-01 1.086990789815e-01 9.344179207682e-02
8.032605785014e-02 6.905128236880e-02 5.935906385039e-02 5.102727046220e-02
和config_id
迁移到picked
之外,并将xs:all
从maxOccurs="unbounded"
的子项迁移到{{1}本身。xs:all
迁移到xs:all
,并使用XSD 1.1断言强制执行其他出现约束。