I have this xml-Schema:
We also had this problem. The reason was the address of the schema http:://xyz.xsd was replaced with https:://xyz.xsd. Our schema library was not able to forward to the https address via http one. So we simply changed the http adresses to https ones in the xml file.
Stadt
and Tabellenplatz
mustn't be xml elements but need to be attributes of the element Fussballmannschaft
. This pattern repeats with the inner elements.
The schema also lacks structures to express repetition of elements (namely the Spieler
element) and choices between player roles (Torwart
,Verteidiger
,Stuermer
).
The use of the xs:keyref
in the schema definition appears to be incomplete - the referenced keys are not specified as xs:key
elements. In order to demonstrate this use, a new root element Fussball
is defined, which should reflect the intent of the schema to formalize the notion of soccer teams. This new root element harbors the key and keyref definitions for the club name attribute and will be needed anyway as soon as multiple teams are to be represented in in a file (there must be a single root element in an xml file ).
The following pair of schema and sample passes the validation.
Schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="Fussball">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="Fussballmannschaft">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="Spieler" maxOccurs="unbounded">
<xs:complexType mixed="true">
<xs:choice>
<xs:element name="Torwart">
<xs:complexType>
<xs:attribute name="GehalteneElfmeter" type="xs:integer" />
<xs:attribute name="ID_Torwart" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="Verteidiger">
<xs:complexType>
<xs:attribute name="GewonneneZweikaempfe" type="xs:integer" />
<xs:attribute name="ID_Verteidiger" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="Stuermer">
<xs:complexType>
<xs:attribute name="GeschosseneTore" type="xs:integer" />
<xs:attribute name="ID_Stuermer" type="xs:integer"/>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="I_D" type="xs:string" />
<xs:attribute name="SpielerID" type="xs:integer" />
<xs:attribute name="Spielername" type="xs:string" />
</xs:complexType>
</xs:element><!-- Spieler -->
</xs:sequence>
<xs:attribute name="Name" type="xs:string" />
<xs:attribute name="Stadt" type="xs:string" />
<xs:attribute name="Tabellenplatz" type="xs:string" />
</xs:complexType>
<xs:key name="k-Spieler">
<xs:selector xpath="./Spieler"/>
<xs:field xpath="@SpielerID"/>
</xs:key>
<xs:keyref name="kref-Spieler" refer="k-Spieler">
<xs:selector xpath="./Spieler/Stuermer|./Spieler/Torwart|./Spieler/Verteidiger"/>
<xs:field xpath="@ID_Stuermer|@ID_Torwart|@ID_Verteidiger"/>
</xs:keyref>
</xs:element><!-- Fussballmannschaft -->
</xs:sequence>
</xs:complexType>
<!--
A 'key' tells you how to uniquely reference an element instance - eg. one among several soccer teams.
-->
<xs:key name="k-Verein">
<xs:selector xpath="./Fussballmannschaft"/>
<xs:field xpath="@Name"/>
</xs:key>
<!--
A 'keyref' specifies that some attribute value(s) are not only constrained by their datatype but must also uniquely identify a certain element in the file - a semantic relationship is established.
-->
<xs:keyref name="kref-Verein" refer="k-Verein">
<xs:selector xpath="./Fussballmannschaft/Spieler"/>
<xs:field xpath="@I_D"/>
</xs:keyref>
</xs:element><!-- Fussball -->
</xs:schema>
XML:
<Fussball>
<Fussballmannschaft Name="BVB" Stadt="Dortmund" Tabellenplatz="3">
<Spieler SpielerID="1" I_D="BVB" Spielername="Oliver">
<Torwart GehalteneElfmeter="20" ID_Torwart="1"/>
</Spieler>
<Spieler SpielerID="2" I_D="BVB" Spielername="Peter">
<Verteidiger GewonneneZweikaempfe="20" ID_Verteidiger="2"/>
</Spieler>
<Spieler SpielerID="3" I_D="BVB" Spielername="Paul">
<Stuermer GeschosseneTore="20" ID_Stuermer="3"/>
</Spieler>
</Fussballmannschaft>
</Fussball>
References
key
and keyref
The real reason you're getting this error,
S4s-elt-character: Non-whitespace Characters Are Not Allowed In Schema Elements Other Than 'xs:appinfo' And 'xs:documentation
is that you're attempting to validate your XML file as an XSD file.
So, fix the way you're invoking your validating parser so that you're validating your XML file against your XSD. See How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?
Additionally, there are a slew of other problems with your XSD itself. See collapsar's answer for help there.