我有一个与某些XSD相关联的XML。我在XSD中包含了XML中的所有元素,包括Root元素。在验证来自此XSD的XML时,它表示缺少CAS(这是根元素)。
有人知道如何解决这个问题吗?
XML:
<?xml version="1.0"?>
<CAS xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="CASNamespace ..\..\CAS_backup.xsd">
<name>CAS SD</name>
<casBaseURL>www.sws.bfh.ch/studium/vorlesungen/</casBaseURL>
<course id="C-jav">
<name>Java</name>
<teacher ref="T-joh"/>
<lessons>40</lessons>
<language>de</language>
<language>en</language>
<url>sd-java.xhtml</url>
<weight>1.8</weight>
</course>
<course id="C-xml">
<name>XML Technologien</name>
<teacher ref="T-exe"/>
<lessons>24</lessons>
<project>8</project>
<language>de</language>
<language>en</language>
<url>sd-xml.xhtml</url>
<weight>1.6</weight>
</course>
<course id="C-rdb">
<name>Relationale Datenbanken</name>
<teacher ref="T-bas"/>
<lessons>24</lessons>
<project>8</project>
<language>de</language>
<language>en</language>
<language>fr</language>
<url>sd-rdb.xhtml</url>
<weight>1.6</weight>
</course>
<course id="C-da">
<name>Datenstrukturen und Algorithmen</name>
<teacher ref="T-rit"/>
<lessons>48</lessons>
<language>de</language>
<language>en</language>
<url>sd-algodata.xhtml</url>
<weight>1.8</weight>
</course>
<course id="C-gui">
<name>GUI/Ergonomie</name>
<teacher ref="T-joh"/>
<teacher ref="T-nom"/>
<lessons>24</lessons>
<project>16</project>
<language>de</language>
<language>en</language>
<url>sd-gui.xhtml</url>
<weight>1.6</weight>
</course>
<student id="P-001">
<name>
<firstName>Roberto</firstName>
<lastName>Campione</lastName>
</name>
<dateOfBirth>1970-12-12</dateOfBirth>
<address>
<street>
<name>Bahnhofstrasse</name>
<number>12</number>
<addition>a</addition>
</street>
<postalCode>4000</postalCode>
<city>Basel</city>
<country>Schweiz</country>
</address>
<ratings>
<rating ref="C-xml"><grade>85</grade></rating>
<rating ref="C-da"><grade>82</grade></rating>
</ratings>
</student>
<student id="P-002">
<name>
<firstName>Willis</firstName>
<middleName>R.</middleName>
<lastName>Pattern</lastName>
</name>
<dateOfBirth>1975-10-12</dateOfBirth>
<address>
<street>
<name>Hauptstrasse</name>
<number>10</number>
</street>
<postalCode>6000</postalCode>
<city>Luzern</city>
<country>Schweiz</country>
</address>
<ratings>
<rating ref="C-da"><grade>45</grade></rating>
<rating ref="C-xml"><grade>75</grade></rating>
<rating ref="C-jav"><grade>75</grade></rating>
</ratings>
</student>
<student id="P-003">
<name>
<firstName>Anna</firstName>
<middleName>Maria</middleName>
<lastName>Muster</lastName>
</name>
<dateOfBirth>1978-10-29</dateOfBirth>
<address>
<street>
<name>Langstrasse</name>
<number>8</number>
</street>
<postalCode>3000</postalCode>
<city>Bern</city>
<country>Schweiz</country>
</address>
<ratings>
<rating ref="C-da"><grade>75</grade></rating>
<rating ref="C-rdb"><grade>96</grade></rating>
<rating ref="C-jav"><grade>88</grade></rating>
<rating ref="C-gui"><grade>78</grade></rating>
</ratings>
</student>
<student id="P-004">
<name>
<firstName>Hans</firstName>
<middleName>Jochen</middleName>
<lastName>Musterhans</lastName>
</name>
<dateOfBirth>1980-08-12</dateOfBirth>
<address>
<street>
<name>Langgasse</name>
<number>4</number>
</street>
<postalCode>8000</postalCode>
<city>Winterthur</city>
<country>Schweiz</country>
</address>
<ratings>
<rating ref="C-da"><grade>95</grade></rating>
<rating ref="C-rdb"><grade>92</grade></rating>
<rating ref="C-jav"><grade>78</grade></rating>
<rating ref="C-xml"><grade>76</grade></rating>
<rating ref="C-gui"><grade>88</grade></rating>
</ratings>
</student>
<student id="P-005">
<name>
<firstName>Christina</firstName>
<lastName>Muster</lastName>
</name>
<dateOfBirth>1968-04-22</dateOfBirth>
<address>
</CAS>
XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="CASNamespace" xmlns="CASNamespace" xmlns:msdata="urn:schemas- microsoft-com:xml-msdata">
<xs:element name="CAS" type="CASType"/>
<xs:complexType name="CASType">
<xs:sequence>
<xs:element ref="name"/>
<!--<xs:element ref="casBaseURL"/>-->
<xs:element maxOccurs="unbounded" ref="course"/>
<xs:element maxOccurs="unbounded" ref="student"/>
<xs:element maxOccurs="unbounded" ref="teacher"/>
<!--<xs:element ref="courseParticipants"/>-->
</xs:sequence>
</xs:complexType>
<xs:element name="course">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="lessons" type="xs:string" minOccurs="1" maxOccurs="50" />
<xs:element name="project" type="xs:string" minOccurs="0"/>
<xs:element name="url" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z].*.xhtml"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="weight" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:float">
<xs:pattern value="[0-9]\.[0-9]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element ref="teacher" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="language" nillable="false" minOccurs="1" maxOccurs="4">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="language_Text" msdata:Ordinal="0">
<xs:extension base="xs:string" />
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element ref="student" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="id">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[C]-[a-z][A-Z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="ref" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="teacher">
<xs:complexType>
<xs:sequence>
<xs:element ref="name" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="ref" type="xs:string" />
<xs:attribute name="id">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[T]-[a-z][A-Z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="student">
<xs:complexType>
<xs:sequence>
<xs:element name="dateOfBirth" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="Year">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1920"/>
<xs:maxInclusive value="2000"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Month">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="12"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Day">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="31"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element ref="name" minOccurs="1" maxOccurs="unbounded" />
<xs:element name="address" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="postalCode" minOccurs="4" maxOccurs="5">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="city" type="xs:string" minOccurs="0" />
<xs:element name="country" type="xs:string" minOccurs="0" />
<xs:element name="street" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="number" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="addition" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ratings" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="rating" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="grade" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<xs:attribute name="ref" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[P]-[a-z][A-Z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="ref" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="name">
<xs:complexType>
<xs:sequence>
<xs:element name="firstName" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="middleName" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="lastName" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z].*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
此致
乌斯曼
答案 0 :(得分:1)
此外,您的XML文档格式不正确。您可以使用W3C验证器http://validator.w3.org/查看“地址”(第157行)和“学生”(第151行)的结束标记丢失。
我不认为反斜杠在这里是个好主意xsi:schemaLocation="CASNamespace ..\..\CAS_backup.xsd"
...
答案 1 :(得分:0)
您的Xml文档将xmlns="http://www.w3schools.com"
指定为其默认命名空间,而您的架构将targetNamespace="CASNamespace" xmlns="CASNamespace"
指定为目标命名空间。
将Xml文档中的xmlns="http://www.w3schools.com"
更改为xmlns="CASNamespace"
,您的文档仍然无法验证,因为它会抱怨它需要元素<course/>
而不是<casBaseURL />
。< / p>