Reputation: 183
i know i have posted this question several times. but i'm now getting a new error, that i need help with. here is the error in which i am receiving. "s4s-elt-invalid-content.1: The content of '#AnonType_orders' is invalid. Element 'element' is invalid, misplaced, or occurs too often."
here is my xsd file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="reach">
<xs:restriction base = "xs:integer">
<xs:enumeration value = "50" />
<xs:enumeration value = "75" />
<xs:enumeration value = "100" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name = "language">
<xs:restriction base = "xs:string">
<xs:enumeration value = "Spanish" />
<xs:enumeration value = "Chinese" />
<xs:enumeration value = "English" />
<xs:enumeration value = "German" />
<xs:enumeration value = "French" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="caseColor">
<xs:restriction base="xs:string">
<xs:enumeration value="Lemonde" />
<xs:enumeration value="Strawberry" />
<xs:enumeration value="Lime" />
<xs:enumeration value="Blueberry" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="numOfBat">
<xs:restriction base="xs:integer">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
<xs:enumeration value="4" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="numOfCam">
<xs:restriction base="xs:string">
<xs:pattern value="1|2" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="volt">
<xs:restriction base="xs:string">
<xs:enumeration value="110-120" />
<xs:enumeration value="220-240" />
</xs:restriction>
</xs:simpleType>
<xs:element name="orders">
<xs:complexType>
<xs:element name ="order" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="custName" type ="xs:string" />
<xs:attribute name ="custID" />
<xs:element name="case" type="xs:caseColor" >
</xs:element>
<xs:element name="batteries" type="xs:numOfBat" default =
"1">
</xs:element>
<xs:element name="recharger" type="xs:volt" />
<xs:element name="arm">
<xs:element name ="reaches" minOccurs="2" maxOccurs="3"
type="xs:reach" />
</xs:element>
<xs:element name ="camera" type="xs:numOfCam" />
<xs:element name = "speech" type="xs:language" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:schema>
here is my xml file:
<?xml version="1.0" encoding="UTF-8"?>
<orders>
<order>
<custName custID="11223"> John Doe </custName>
<case> Strawberry </case>
<batteries> 2 </batteries>
<recharger> 110-120 V </recharger>
<arm>
<reach> 50 </reach>
<reach> 100 </reach>
</arm>
<camera> 2 </camera>
<speech> Spanish </speech>
</order>
<order>
<custName custID="45392"> Jane Camp </custName>
<case> Lime </case>
<batteries> 4 </batteries>
<recharger> 220-240 V </recharger>
<arm> 3
<reach> 75 </reach>
<reach> 75 </reach>
<reach> 100 </reach>
</arm>
<camera> 1 </camera>
<speech> Chinese </speech>
</order>
<order>
<custName custID="69482"> George Carlton </custName>
<case> Blueberry </case>
<batteries> 1 </batteries>
<recharger> 110-120 V </recharger>
<arm>
<reach> 75 </reach>
<reach> 100 </reach>
</arm>
<camera> 2 </camera>
<speech> French </speech>
</order>
</orders>
Upvotes: 1
Views: 7679
Reputation: 8741
Your xsd
is badly formed, specifically your orders
element. You are also referencing the wrong namespace for your custom types. I'll run down the issues that i see.
First: your orders
node is defined as a xs:complexType
and you have an order
element as the child of complexType
, but element is not a permitted child node. You need to put xs:sequence
or xs:all
in between:
<xs:element name="orders">
<xs:complexType>
<xs:sequence>
<xs:element name ="order" maxOccurs="unbounded">
<!-- existing nodes -->
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Next: your arm
element has 1 child element, but xs:element
is not permitted in this context. You need to define it as a complexType
and then sequence
or all
again.
<xs:element name="arm">
<xs:complexType>
<xs:sequence>
<xs:element name ="reaches" minOccurs="2" maxOccurs="3" type="reach" />
</xs:sequence>
</xs:complexType>
</xs:element>
Third: your custId
attribute is not defined in the correct location. xs:attributes
have to be defined as a child node under the element in which they are defined as an attribute, however xs:simpleType cannot have an attribute node, so you need to instead define it as a complexType. Here's a possible solution to your problem here:
<xs:element name="custName">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="custID" type="xs:int" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
And lastly: when you reference all of your custom types (reach
, numOfBat
, volt
, etc), you are referencing them as part of the xs:
namespace, however these types are not defined in the xs:
namespace. Since you don't define a targetNamespace for the XSD, your custom types become part of the default namespace. You just need to remove the xs:
from the type.
For example, you should be declaring them like: type="reach"
, type="numOfBat"
, type="caseColor"
, etc
Upvotes: 3
Reputation: 163262
I don't know what tool you are using for validation, but the messages it produces seem to be rather unhelpful. For information, here are the messages produced by Saxon:
Saxon-EE 9.5.0.1J from Saxonica
Java version 1.6.0_27
Using license serial number M008277
Loading schema document file:/Users/mike/Desktop/temp/test.xsd
Error at xs:element on line 48 column 49 of test.xsd:
Element xs:element cannot appear here: expected one of {choice, sequence, assert,
openContent, annotation, attributeGroup, anyAttribute, simpleContent, all, attribute,
group, complexContent}
Error at xs:attribute on line 52 column 48 of test.xsd:
Element <xs:attribute> is not allowed as a child of <xs:sequence>
Error at xs:element on line 61 column 19 of test.xsd:
Element xs:element cannot appear here: expected one of {annotation, simpleType, key,
complexType, keyref, unique, alternative}
Error at xs:element on line 61 column 19 of test.xsd:
Element <xs:element> is not allowed as a child of <xs:element>
Schema processing failed: 4 errors were found while processing the schema
I hope you find these clearer. Essentially, the problem is that xs:element cannot appear as a child of xs:complexType: you probably need something like xs:sequence in between.
Upvotes: 0