没有加属性约束,为何xml文件没有报错
来源:2-5 XML Schema
weixin_慕设计9597346
2020-04-12 18:37:40
<?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema"> <complexType name="teaching-plan"> <sequence> <element name="course" minOccurs="1" maxOccurs="100"> <complexType> <sequence> <element name="course-name" type="string"></element> <element name="course-hour"> <simpleType> <restriction base="integer"> <minInclusive value="20"></minInclusive> <maxInclusive value="110"></maxInclusive> </restriction> </simpleType> </element> <element name="exam-form" type="string"></element> </sequence> </complexType> </element> </sequence> </complexType> </schema>

5回答
同学你好,xsd文件中<teaching_plan xmlns:xsi="http://www.w3.org/2001/XMLSchame-instance" xsi:idNamespaceSchemaLocation="plan.xsd">写错了。建议同学将正确的复制到文件中,自己输入可能会出错。修改如下图:
正确的应该是<teaching-plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="plan.xsd">
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
weixin_慕设计9597346
提问者
2020-04-13
<?xml version="1.0" encoding="UTF-8"?> <teaching_plan xmlns:xsi="http://www.w3.org/2001/XMLSchame-instance" xsi:idNamespaceSchemaLocation="plan.xsd"> <course id="111"> <course-name>大学英语</course-name> <class-hour>36</class-hour> <exam-form>考试</exam-form> </course> <course> <course-name>高等数学</course-name> <class-hour>70</class-hour> <exam-form>考试</exam-form> </course> <course> <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="course-hour"> <simpleType> <restriction base="integer"> <minInclusive value="20"></minInclusive> <maxInclusive value="110"></maxInclusive> </restriction> </simpleType> </element> <element name="exam-form" type="string"></element> </sequence> </complexType> </element> </sequence> </complexType> </element> </schema>
好帮手慕阿慧
2020-04-13
同学你好,请检查一下eclipse中xml校验配置:选择Windows-->Perferences,左侧选择Validation,确保右侧xml校验的勾选了,最后点击Apply and Close。配置完成后,重新打开xml文件。如下图:

xml文件中teaching_plan写错了,应该将下划线改为中划线。如果不行,建议同学新建一个项目试试。如果还不行请同学将xsd和xml文件都以文本的形式贴出来,方便老师在本地测试。
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
weixin_慕设计9597346
提问者
2020-04-13
<?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="course-hour"> <simpleType> <restriction base="integer"> <minInclusive value="20"></minInclusive> <maxInclusive value="110"></maxInclusive> </restriction> </simpleType> </element> <element name="exam-form" type="string"></element> </sequence> </complexType> </element> </sequence> </complexType> </element> </schema>

好帮手慕阿慧
2020-04-12
同学你好,xsd文件中没有声明根节点element。修改如下图:

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
相似问题