这是我的xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<teaching-plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="teaching-plan.xsd">
<course id="1">
<course-name>
大学英语
</course-name>
<class-hour>
36
</class-hour>
<exam-form>
考试
</exam-form>
</course>
<course id="2">
<course-name>
高等数学
</course-name>
<class-hour>
70
</class-hour>
<exam-form>
考试
</exam-form>
</course>
<course id="3">
<course-name>
计算机应用基础
</course-name>
<class-hour>
108
</class-hour>
<exam-form>
上机考试
</exam-form>
</course>
</teaching-plan>
这是我的模式:
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="teaching-plan">
<complexType>
<sequence>
<element name="course" minOccurs="1" maxOccurs="100">
<complexType>
<sequence>
<element name="course-name" type="string"></element>
<element name="class-hour" >
<simpleType>
<restriction base="integer">
<minInclusive value="2"></minInclusive>
<maxInclusive value="5"></maxInclusive>
</restriction>
</simpleType>
</element>
<element name="exam-form" type="string"></element>
</sequence>
<attribute name="id" type="string" use="required"></attribute>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
想法编辑器不断告诉我,必须声明元素教学计划,但我确实在模式中声明了。 这可能是编辑器问题还是我错过了什么? 刚开始学习xml和模式,仍然有很多问题。 谁能告诉我如何解决这个问题? 谢谢。
答案 0 :(得分:0)
这是我从命令行使用Saxon运行验证的方法:
Validation error on line 7 column 21 of test.xml:
FORG0001: The content "\n 36\n " of element <class-hour> does not match
the required simple type. Value "36" contravenes the maxInclusive facet "5" of the type of
element class-hour
See http://www.w3.org/TR/xmlschema-2/#cvc-datatype-valid clause 1
Validation error on line 18 column 21 of test.xml:
FORG0001: The content "\n 70\n " of element <class-hour> does not match
the required simple type. Value "70" contravenes the maxInclusive facet "5" of the type of
element class-hour
See http://www.w3.org/TR/xmlschema-2/#cvc-datatype-valid clause 1
Validation error on line 29 column 21 of test.xml:
FORG0001: The content "\n 108\n " of element <class-hour> does not match
the required simple type. Value "108" contravenes the maxInclusive facet "5" of the type
of element class-hour
See http://www.w3.org/TR/xmlschema-2/#cvc-datatype-valid clause 1
Validation error on line 36 column 17 of test.xml:
FORG0001: Three validation errors were reported. First error: The content "\n
36\n " of element <class-hour> does not match the required simple type. Value "36"
contravenes the maxInclusive facet "5" of the type of element class-hour
Validation complete: errors found
这告诉我们的是,您的架构基本上没有任何错误。该实例对架构无效,但这很好。
这并不能直接帮助您知道尝试运行验证的问题-只是它告诉您与运行方式有关,而从根本上讲,这不是代码方面的问题。
>我会针对您的模式提出一个建议:maxOccurs =“ 100”是因为确实存在对多少门课程的基本限制,还是因为您认为有一个限制似乎是一个好主意? ?我建议,首先,最好没有限制,除非您确实需要一个限制;其次,评估maxOccurs的值可能非常昂贵。构造简单的有限状态自动机进行验证的模式验证器最终将具有大量状态。