验证xml和xsd时出错
我有一个简单的xml验证xml和xsd时出错,xml,xsd,xml-validation,Xml,Xsd,Xml Validation,我有一个简单的xml <?xml version="1.0" encoding="UTF-8"?> <school xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com Projekt.xsd"> <personen> <p
<?xml version="1.0" encoding="UTF-8"?>
<school xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com Projekt.xsd">
<personen>
<person id="1">
<name>A</name>
<kuerzel>a</kuerzel>
<email>a@a.ch</email>
</person>
<person id="2">
<name>B</name>
<kuerzel>b</kuerzel>
<email>b@b.ch</email>
</person>
<person id="3">
<name>C</name>
<kuerzel>c</kuerzel>
<email>c@c.ch</email>
</person>
</personen>
</school>
A.
A.
a@a.ch
B
B
b@b.ch
C
C
c@c.ch
并定义了以下xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="school">
<xs:complexType>
<xs:sequence>
<xs:element name="personen">
<xs:complexType>
<xs:sequence>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="kuerzel" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
在联机验证工具中验证这两个文件时,会出现以下错误:
Cvc复杂类型.2.4.d:发现以开头的内容无效
元素“person”。此时不需要任何子元素。。线
“10”,第“18”列
为什么我会犯这个错误?
我的xsd文件有什么问题?我似乎找不到错误:(
提前感谢您必须指定person元素可以出现多次 像这样扩展您的xsd人员:
<xs:element name="person" maxOccurs="unbounded">
通过模式,我们可以使用maxOccurs和minOccurs属性定义元素可能出现的次数。maxOccurs指定元素的最大出现次数,minOccurs指定元素的最小出现次数。maxOccurs和minOccurs的默认值均为1!您必须指定,person元素可以出现多次 像这样扩展您的xsd人员:
<xs:element name="person" maxOccurs="unbounded">
通过模式,我们可以使用maxOccurs和minOccurs属性定义元素可能出现的次数。maxOccurs指定元素的最大出现次数,minOccurs指定元素的最小出现次数。maxOccurs和minOccurs的默认值均为1!您必须指定,person元素可以出现多次 像这样扩展您的xsd人员:
<xs:element name="person" maxOccurs="unbounded">
通过模式,我们可以使用maxOccurs和minOccurs属性定义元素可能出现的次数。maxOccurs指定元素的最大出现次数,minOccurs指定元素的最小出现次数。maxOccurs和minOccurs的默认值均为1!您必须指定,person元素可以出现多次 像这样扩展您的xsd人员:
<xs:element name="person" maxOccurs="unbounded">
通过模式,我们可以使用maxOccurs和minOccurs属性定义元素可能出现的次数。maxOccurs指定元素的最大出现次数,minOccurs指定元素的最小出现次数。maxOccurs和minOccurs的默认值均为1!问题出在哪里如果不定义maxoccurs,则可以通过这种方式解决问题
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="school">
<xs:complexType>
<xs:sequence>
<xs:element name="personen" maxOccurs="unbounded">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:sequence>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="kuerzel" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
问题在于您没有定义maxoccurs,您可以通过这种方式解决问题
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="school">
<xs:complexType>
<xs:sequence>
<xs:element name="personen" maxOccurs="unbounded">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:sequence>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="kuerzel" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
问题在于您没有定义maxoccurs,您可以通过这种方式解决问题
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="school">
<xs:complexType>
<xs:sequence>
<xs:element name="personen" maxOccurs="unbounded">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:sequence>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="kuerzel" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
问题在于您没有定义maxoccurs,您可以通过这种方式解决问题
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="school">
<xs:complexType>
<xs:sequence>
<xs:element name="personen" maxOccurs="unbounded">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:sequence>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="kuerzel" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>