0

XSD<schema>标签:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.cmu.edu/ns/blank"
    targetNamespace="http://www.cmu.edu/ns/blank"
    elementFormDefault="qualified"> 

XML 的根,<people>标记。

<people
    xmlns="http://www.cmu.edu/ns/blank"
    xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.cmu.edu/ns/blank student.xsd">   

我怎么会出错:

cvc-elt.1.a: Cannot find the declaration of element 'people'  

我知道它与命名空间有关,但我不知道是什么。

请帮忙

XML

<?xml version="1.0" encoding="UTF-8" ?>
<!-- <!DOCTYPE people SYSTEM "validator.dtd"> -->


    <people
        xmlns="http://www.cmu.edu/ns/blank"
        xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.cmu.edu/ns/blank student.xsd"> 

        <student>
            <name>John</name>
            <course>Computer Technology</course>
            <semester>6</semester>
            <scheme>E</scheme>
        </student>

        <student>
            <name>Foo</name>
            <course>Industrial Electronics</course>
            <semester>6</semester>
            <scheme>E</scheme>
        </student>
    </people>  

XSD

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns="http://www.cmu.edu/ns/blank"
        targetNamespace="http://www.cmu.edu/ns/blank"
        elementFormDefault="qualified">
    <xs:element name="people">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="student" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="name" type="xs:string" />
                            <xs:element name="course" type="xs:string" />
                            <xs:element name="semester">
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:enumeration value="1" />
                                        <xs:enumeration value="2" />
                                        <xs:enumeration value="3" />
                                        <xs:enumeration value="4" />
                                        <xs:enumeration value="5" />
                                        <xs:enumeration value="6" />
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:element>
                            <xs:element name="scheme">
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:pattern value = "E|C" />
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
4

1 回答 1

1

唯一不起作用的是架构位置属性的命名空间。XML 模式实例命名空间是:

http://www.w3.org/2001/XMLSchema-instance

代替:

http://www.w3c.org/2001/XMLSchema-instance(你在w3c中放了一个c

对于给定的 XML,错误是

The 'http://www.w3c.org/2001/XMLSchema-instance:schemaLocation' attribute is not declared.

于 2013-05-11T00:52:00.530 回答