引入xsd时候报错

引入xsd时候报错

1
<br>

<?xml version="1.0" encoding="UTF-8"?>

<!-- <!DOCTYPE teaching-plan SYSTEM "plan-data.dtd" >   -->

<teaching-plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  

xsi:noNamespaceSchemaLocation="XMLSchema.xsd" >//报错位置,没提示,啥都没,就一个x

<coure  no="2321">

<coure-name>大学英语</coure-name>

<class-hour>36</class-hour>

<exam-form>考试</exam-form>

</coure>

<coure no="2">

<course-name>高等数学</course-name>

<class-hour>70</class-hour>

<exam-form>考试</exam-form>

</coure>

<coure no="3">

<course-name>计算机应用基础</course-name>

<class-hour>108</class-hour>

<exam-form>上机考试</exam-form>

</coure>

</teaching-plan>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
    <element name="techhing-plan">
        <complexType>
            <sequence>
                <element name="coure">
                    <complexType>
                        <sequence>
                            <element name="coure-name" type="string"></element>
                            <element name="class-hour"  type="float"></element>
                            <element name="exam" type="string"></element>
                        </sequence>
                    </complexType>
                </element>
            </sequence>
        </complexType>
    </element>
</schema>


正在回答

登陆购买课程后可参与讨论,去登陆

3回答

同学你好!

  1. 你的xml和xsd中的teaching-plan 并不匹配呢

    xml中你写的teaching-plan

    http://img1.sycdn.imooc.com//climg/5da91efd09528e6705360100.jpg

    xsd中你写的teachhing-plan

    http://img1.sycdn.imooc.com//climg/5da91fed09a5f3f902870071.jpg


    建议同学将上面两者统一一下

  2. 你的course-name标签,xml和xsd中写的也不统一:

    xml中写的course-name:

    http://img1.sycdn.imooc.com//climg/5da91f8009b3438703480121.jpg

    xsd中写的coure-name:

    http://img1.sycdn.imooc.com//climg/5da91fdb09b400a704950073.jpg

    建议同学将上面的两者也统一一下

  3. 你的no报错,因为在xsd中你定义的是id,并且你的位置放错了,并且在xml中应该为id

    http://img1.sycdn.imooc.com//climg/5da9205809f2de3c06740558.jpg

  4. 老师对同学的代码,做了修改,你可以参考一下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0" encoding="UTF-8"?>
<teaching-plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
 
xsi:noNamespaceSchemaLocation="XMLSCHEma.xsd" >
 
<coure  id="2321">
 
<coure-name>大学英语</coure-name>
 
<class-hour>36</class-hour>
 
<exam-form>考试</exam-form>
 
</coure>
 
<coure id="2">
 
<coure-name>高等数学</coure-name>
 
<class-hour>70</class-hour>
 
<exam-form>考试</exam-form>
 
</coure>
 
<coure id="3">
 
<coure-name>计算机应用基础</coure-name>
 
<class-hour>108</class-hour>
 
<exam-form>上机考试</exam-form>
 
</coure>
 
</teaching-plan>

xsd:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?xml version="1.0" encoding="UTF-8"?>
 
<schema xmlns="http://www.w3.org/2001/XMLSchema">
 
    <element name="teaching-plan">
 
        <complexType>
 
            <sequence>
 
                <element name="coure" maxOccurs="1000">
 
        <complexType>
 
        <sequence>
 
            <element name="coure-name" type="string"></element>
 
            <element name="class-hour"  >
         
                <simpleType>
         
                    <restriction base="integer">
         
                    <maxInclusive value="110"></maxInclusive>
         
                    <minInclusive value="20"></minInclusive>
         
                    </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>

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

提问者 cccca 2019-10-17 20:16:21

<teaching-plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  

xsi:noNamespaceSchemaLocation="XMLSCHEma.xsd" >//报错

<coure  no="2321">

<coure-name>大学英语</coure-name>

<class-hour>36</class-hour>

<exam-form>考试</exam-form>

</coure>

<coure no="2">

<course-name>高等数学</course-name>

<class-hour>70</class-hour>

<exam-form>考试</exam-form>

</coure>

<coure no="3">

<course-name>计算机应用基础</course-name>

<class-hour>108</class-hour>

<exam-form>上机考试</exam-form>

</coure>

</teaching-plan>


<?xml version="1.0" encoding="UTF-8"?>

<schema xmlns="http://www.w3.org/2001/XMLSchema">

<element name="teachhing-plan">

<complexType>

<sequence>

<element name="coure" maxOccurs="1000">

<complexType>

<sequence>

<element name="coure-name" type="string"></element>

<element name="class-hour" >

<simpleType >

<restriction base="integer">

<maxInclusive value="110"></maxInclusive>

<minInclusive value="20"></minInclusive>

</restriction>

</simpleType>

</element>

<element name="exam-form" type="string"></element>

</sequence>

</complexType>

</element>

</sequence>

<attribute name="id" type="string"  use="required"></attribute>

</complexType>

</element> 

</schema>


好帮手慕小班 2019-10-17 17:50:40

同学你好,1、这里同学的xsd文件中teaching-plan单词书写有误呐,注意单词的正确书写呐

http://img1.sycdn.imooc.com//climg/5da83848098c16f304010076.jpg

    2、在xsd文件中,name是exam,但是在xml文件中:

http://img1.sycdn.imooc.com//climg/5da838ea0929854802950037.jpg

    3、在xsd文件中没有定义no属性,也就是id属性,在xml文件中有no属性,程序会报错的呐,建议在xsd中添加

<attribute name="no" type="string" use="required"></attribute>

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

  • 提问者 cccca #1
    好的,以上会注意的,但我的是这句话报错,没提示,啥都没,就一个红x在前面 <teaching-plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="XMLSCHEma.xsd" >
    2019-10-17 17:57:37
  • 提问者 cccca #2
    你说的问题我都改了,还是这个报错
    2019-10-17 18:01:59
  • 好帮手慕小班 回复 提问者 cccca #3
    同学你好,这里建议同学将修改后的代码贴出,便于老师定位问题,注意贴在我要回答中,不要贴在回复里,会失去代码格式。继续加油 祝:学习愉快~
    2019-10-17 18:19:51
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码