S4s-elt-invalid-content.1: 元素 'element' 无效、放错位置或出现太频繁
S4s-elt-invalid-content.1: Element 'element' Is Invalid, Misplaced, Or Occurs Too Often
我正在尝试使用给定的架构验证我的 XML,但一直收到此错误。
S4s-elt-invalid-content.1: The Content Of 'coreTextType' Is Invalid.
Element 'element' Is Invalid, Misplaced, Or Occurs Too Often.
这是我的 XML
<?xml version="1.0" encoding="UTF-8"?>
<authors>
<coretext>
<author id="VH">
<name>Victor Hugo</name>
<nationality>French</nationality>
<rating>4.00</rating>
</author>
<author period="classical">
<name>Sophocles</name>
<nationality>Greek</nationality>
<rating>15.00</rating>
</author>
<author>
<name>Nikolai Gogol</name>
<nationality>Russian</nationality>
<rating>11.00</rating>
</author>
</coretext>
<author>
<name>Leo Tolstoy</name>
<nationality>Russian</nationality>
<rating>12.00</rating>
</author>
<author id ="AR">
<name>Alexander Pushkin</name>
<nationality>Russian</nationality>
<rating>13.88</rating>
</author>
<author period="classical">
<name>Plato</name>
<nationality>Greek</nationality>
<rating>20.15</rating>
</author>
</authors>
这是我的架构
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="authors">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="coretext" type="coreTextType" />
<xs:element name="author" type="authorType" />
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="coreTextType">
<xs:element name="author" type="authorType" maxOccurs="unbounded"/>
</xs:complexType>
<xs:complexType name="authorType">
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="nationality" type="xs:string" />
<xs:element name="rating" type="xs:integer" />
<xs:attribute name="id" type="xsd:string" />
<xs:attribute name="binding" type="xsd:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
有人能给我指出正确的方向吗?
你的XML没问题,但是你的XSD有很多错误:
- A
xs:complexType
不能直接将 xs:element
作为 child;裹
它首先出现在 xs:sequence
中。 (这是与您当前的错误消息相关的错误。)
xs:attribute
不能出现在xs:sequence
内;将它们移到外面但仍在 xs:complexType
. 之内
xsd:
未定义;你是说 xs:
.
rating
的类型应该是xs:decimal
,不是xs:integer
@binding
应该是 @period
以匹配您的 XML.
XSD
这是您的 XSD 将修复所有错误:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="authors">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="coretext" type="coreTextType" />
<xs:element name="author" type="authorType" />
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="coreTextType">
<xs:sequence>
<xs:element name="author" type="authorType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="authorType">
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="nationality" type="xs:string" />
<xs:element name="rating" type="xs:decimal" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
<xs:attribute name="period" type="xs:string" />
</xs:complexType>
</xs:schema>
它现在将成功验证您的 XML。
我正在尝试使用给定的架构验证我的 XML,但一直收到此错误。
S4s-elt-invalid-content.1: The Content Of 'coreTextType' Is Invalid. Element 'element' Is Invalid, Misplaced, Or Occurs Too Often.
这是我的 XML
<?xml version="1.0" encoding="UTF-8"?>
<authors>
<coretext>
<author id="VH">
<name>Victor Hugo</name>
<nationality>French</nationality>
<rating>4.00</rating>
</author>
<author period="classical">
<name>Sophocles</name>
<nationality>Greek</nationality>
<rating>15.00</rating>
</author>
<author>
<name>Nikolai Gogol</name>
<nationality>Russian</nationality>
<rating>11.00</rating>
</author>
</coretext>
<author>
<name>Leo Tolstoy</name>
<nationality>Russian</nationality>
<rating>12.00</rating>
</author>
<author id ="AR">
<name>Alexander Pushkin</name>
<nationality>Russian</nationality>
<rating>13.88</rating>
</author>
<author period="classical">
<name>Plato</name>
<nationality>Greek</nationality>
<rating>20.15</rating>
</author>
</authors>
这是我的架构
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="authors">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="coretext" type="coreTextType" />
<xs:element name="author" type="authorType" />
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="coreTextType">
<xs:element name="author" type="authorType" maxOccurs="unbounded"/>
</xs:complexType>
<xs:complexType name="authorType">
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="nationality" type="xs:string" />
<xs:element name="rating" type="xs:integer" />
<xs:attribute name="id" type="xsd:string" />
<xs:attribute name="binding" type="xsd:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
有人能给我指出正确的方向吗?
你的XML没问题,但是你的XSD有很多错误:
- A
xs:complexType
不能直接将xs:element
作为 child;裹 它首先出现在xs:sequence
中。 (这是与您当前的错误消息相关的错误。) xs:attribute
不能出现在xs:sequence
内;将它们移到外面但仍在xs:complexType
. 之内
xsd:
未定义;你是说xs:
.rating
的类型应该是xs:decimal
,不是xs:integer
@binding
应该是@period
以匹配您的 XML.
XSD
这是您的 XSD 将修复所有错误:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="authors">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="coretext" type="coreTextType" />
<xs:element name="author" type="authorType" />
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="coreTextType">
<xs:sequence>
<xs:element name="author" type="authorType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="authorType">
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="nationality" type="xs:string" />
<xs:element name="rating" type="xs:decimal" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
<xs:attribute name="period" type="xs:string" />
</xs:complexType>
</xs:schema>
它现在将成功验证您的 XML。