Reputation: 13
I'm working on an XSD for a project, here's what I've got:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Elizabeth schema"
xmlns:elz="http://www.example.org/Elizabeth_schema" elementFormDefault="qualified">
<xs:element name ="year">
<xs:complexType mixed = "true">
<xs:sequence>
<xs:element name="entry">
<xs:complexType mixed ="true">
<xs:simpleContent>
<xs:attribute name ="when" type = "xs:string"/>
<xs:attribute name = "place" type = "xs:string"/>
<xs:element name = "items" type = "xs:string"/>
<xs:element name = "characters">
<xs:complexType>
<xs:attribute name ="character" type = "xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name = "eventscollection">
<xs:complexType>
<xs:attribute name = "type" type = "xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name ="entrytxt">
<xs:complexType>
<xs:any minOccurs = "0"/>
<xs:anyAttribute minOccurs="0"/>
</xs:complexType>
</xs:element>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I haven't pointed the xls at the schema yet because I want to get the schema working first. My IDE is throwing me a bug:
s4s-elt-invalid-content.1: The content of '#AnonType_entryyear' is invalid. Element 'attribute' is invalid, misplaced, or occurs too often.
Line 11 is where I introduce the first attribute under the element "entry." I've found that if I delete line 10 ("simpleContent"), I get the same error but on line 13 where I introduce the first element under "entry."
I'm a beginner with this, and I've done some prodding around the internet but can't seem to figure out what's up with my code. Any thoughts?
Upvotes: 1
Views: 2906
Reputation: 111660
There are a number of problems with your XSD, including
entry
does not have simple content. Change xs:simpleContent
to
xs:sequence
within xs:complexType
.xs:attribute
declarations outside of xs:sequence
.minOccurs
from xs:anyAttribute
.Note that you probably want to remove the spacing surrounding your attribute =
sign -- not required, but it looks rather unconventional, and inconsistent as you have it.
Here is your XSD fully corrected:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Elizabeth schema"
xmlns:elz="http://www.example.org/Elizabeth_schema"
elementFormDefault="qualified">
<xs:element name="year">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="entry">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="items" type="xs:string"/>
<xs:element name="characters">
<xs:complexType>
<xs:attribute name="character" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="eventscollection">
<xs:complexType>
<xs:attribute name="type" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="entrytxt">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0"/>
</xs:sequence>
<xs:anyAttribute/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="when" type="xs:string"/>
<xs:attribute name="place" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Upvotes: 0