I'm new at XML, and I'm getting an error,
S4s-elt-invalid-content.1: The Content Of '#AnonType_queue' Is Invalid. Element 'Sequence' Is Invalid, Misplaced, Or Occurs Too Often
while trying to validate my xml and xsd files and I'm not sure why..
Here is the XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="queue.xsl"?>
<queue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="queue.xsd">
<!DOCTYPE queue SYSTEM "queue.dtd">
<queue>
<link>
<name>Alfa Romeo Giulia</name>
<uri>https://en.wikipedia.org/wiki/Alfa_Romeo_Giulia_(952)</uri>
<prodYear>2015</prodYear>
<tophp>533</tophp>
<availablecolors>
<color1>Alfa Black</color1>
<color2>Alfa White</color2>
<color3>Alfa Rosso</color3>
</availablecolors>
</link>
<link>
<name>Audi A5</name>
<uri>https://en.wikipedia.org/wiki/Audi_A5</uri>
<prodYear>2007</prodYear>
<tophp>444</tophp>
<availablecolors>
<color1>Tango red metallic</color1>
<color2>Gotland Green Metallic</color2>
<color3>Ibis White</color3>
</availablecolors>
</link>
<!--
<link>
<name></name>
<uri></uri>
<prodYear></prodYear>
<tophp></tophp>
<availablecolors>
<color1></color1>
<color2></color2>
<color3></color3>
</availablecolors>
</link>
-->
</queue>
And here is the XSD file:
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="queue">
<xs:complexType>
<xs:Sequence>
<xs:element name="link" />
<xs:complexType>
<xs:element name="name" type="xs:string" />
<xs:element name="uri" type="xs:string" />
<xs:element name="prodYear" type="xs:string" />
<xs:element name="availablecolors" />
<xs:complexType>
<xs:element name="color1" type="xs:string" />
<xs:element name="color2" type="xs:string" />
<xs:element name="color3" type="xs:string" />
</xs:complexType>
</xs:complexType>
</xs:Sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Any help would be appreciated.
CodePudding user response:
Problems and corrections for your XSD and XML follow.
Corrected XSD
Your XSD has a number of problems:
- XML and XSD are case sensitive, so change
xs:Sequence
toxs:sequence
. <xs:element name="link"/>
closes the element before including the intended followingxs:complexType
definition. This happens again withavailablecolors
.- You have missing
xs:sequence
elements underxs:complexType
. - It fails to accommodate multiple
link
elements. - It is missing a declaration for
tophp
.
<?xml version="1.0"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="queue">
<xs:complexType>
<xs:sequence>
<xs:element name="link" maxOccurs="unbounded" >
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="uri" type="xs:string" />
<xs:element name="prodYear" type="xs:string" />
<xs:element name="tophp" type="xs:string" />
<xs:element name="availablecolors" >
<xs:complexType>
<xs:sequence>
<xs:element name="color1" type="xs:string" />
<xs:element name="color2" type="xs:string" />
<xs:element name="color3" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Corrected XML
Your XML has a number of problems preventing it from even being well-formed:
- The doctype,
<!DOCTYPE queue SYSTEM "queue.dtd">
, cannot appear in the middle of the document. - There is an extra opening
queue
tag.
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="queue.xsl"?>
<queue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="queue.xsd">
<link>
<name>Alfa Romeo Giulia</name>
<uri>https://en.wikipedia.org/wiki/Alfa_Romeo_Giulia_(952)</uri>
<prodYear>2015</prodYear>
<tophp>533</tophp>
<availablecolors>
<color1>Alfa Black</color1>
<color2>Alfa White</color2>
<color3>Alfa Rosso</color3>
</availablecolors>
</link>
<link>
<name>Audi A5</name>
<uri>https://en.wikipedia.org/wiki/Audi_A5</uri>
<prodYear>2007</prodYear>
<tophp>444</tophp>
<availablecolors>
<color1>Tango red metallic</color1>
<color2>Gotland Green Metallic</color2>
<color3>Ibis White</color3>
</availablecolors>
</link>
<!--
<link>
<name></name>
<uri></uri>
<prodYear></prodYear>
<tophp></tophp>
<availablecolors>
<color1></color1>
<color2></color2>
<color3></color3>
</availablecolors>
</link>
-->
</queue>