Jump to content

Can't Get My Schema Validated


GewoonM

Recommended Posts

Hi All!I'm relatively new to XML and am busy writing a schema. When I try to validate this, however, I get 6 errors, all the same (but on other lines and with other refs):Error: Invalid content found starting with element 'xs:element'. One of '{"http://www.w3.org/2001/XMLSchema":annotation, "http://www.w3.org/2001/XMLSchema":simpleContent, "http://www.w3.org/2001/XMLSchema":complexContent, "http://www.w3.org/2001/XMLSchema":group, "http://www.w3.org/2001/XMLSchema":all, "http://www.w3.org/2001/XMLSchema":choice, "http://www.w3.org/2001/XMLSchema":sequence, "http://www.w3.org/2001/XMLSchema":attribute, "http://www.w3.org/2001/XMLSchema":attributeGroup, "http://www.w3.org/2001/XMLSchema":anyAttribute}' is expected.Attribute 'ref' is not permitted to appear in element 'xs:element'.Attribute 'minOccurs' is not permitted to appear in element 'xs:element'.Attribute 'maxOccurs' is not permitted to appear in element 'xs:element'.Attribute 'name' must appear on element 'xs:element'. Error Position: <xs:element ref="author" minOccurs="1" maxOccurs="unbounded"/>I don't understand what is wrong with my XML, since an example I found on the web (http://www.xml.com/pub/a/2000/11/29/schemas/part1.html?page=2) DOES work, with practically the same code... Also, I don't understand this errormessage, why are 'ref', 'minOccurs' and 'maxOccurs' not permitted?I've tried looking for this error on the web and I've tried other resources, I just don't seem to be able to figure this out...Thanks a lot for your help!MXML-code:

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">  <!-- definition of simple type elements -->  <xs:element name="title" type="xs:string"/>  <xs:element name="city" type="xs:string"/>  <xs:element name="name" type="xs:string"/>  <xs:element name="year" type="xs:integer"/>  <xs:element name="volume" type="xs:integer"/>  <xs:element name="number" type="xs:integer"/>  <xs:element name="part" type="xs:integer"/>  <!-- definition of attributes -->  <xs:attribute name="from" type="xs:integer"/>  <xs:attribute name="to" type="xs:integer"/>  <xs:attribute name="name" type="xs:string"/>  <!-- definition of complex type elements -->  <xs:element name="author">    <xs:complexType>        <xs:attribute ref="name"/>    </xs:complexType>  </xs:element>    <xs:element name="editor">    <xs:complexType>        <xs:attribute ref="name"/>    </xs:complexType>  </xs:element>    <xs:element name="page">    <xs:complexType>        <xs:attribute ref="name"/>        <xs:attribute ref="to"/>    </xs:complexType>  </xs:element>  <xs:element name="authors">    <xs:complexType>        <xs:element ref="author" minOccurs="1" maxOccurs="unbounded"/>    </xs:complexType>  </xs:element>  <xs:element name="editors">    <xs:complexType>        <xs:element ref="editor" minOccurs="1" maxOccurs="unbounded"/>    </xs:complexType>  </xs:element>    <xs:element name="publisher">    <xs:complexType>      <xs:sequence>        <xs:element ref="city" minOccurs="1" maxOccurs="1"/>        <xs:element ref="name" minOccurs="1" maxOccurs="1"/>      </xs:sequence>    </xs:complexType>  </xs:element>    <xs:element name="book">    <xs:complexType>      <xs:sequence>        <xs:element ref="authors" minOccurs="1" maxOccurs="unbounded"/>        <xs:element ref="year" minOccurs="0" maxOccurs="1"/>        <xs:element ref="title" minOccurs="1" maxOccurs="1"/>        <xs:element ref="publisher" minOccurs="1" maxOccurs="1"/>      </xs:sequence>    </xs:complexType>  </xs:element>    <xs:element name="journal">    <xs:complexType>      <xs:sequence>        <xs:element ref="title" minOccurs="1" maxOccurs="1"/>        <xs:element ref="volume" minOccurs="1" maxOccurs="1"/>        <xs:element ref="number" minOccurs="0" maxOccurs="1"/>        <xs:element ref="part" minOccurs="0" maxOccurs="1"/>      </xs:sequence>    </xs:complexType>  </xs:element>  <xs:element name="journalentry">    <xs:complexType>      <xs:sequence>        <xs:element ref="authors" minOccurs="1" maxOccurs="unbounded"/>        <xs:element ref="year" minOccurs="1" maxOccurs="1"/>        <xs:element ref="title" minOccurs="1" maxOccurs="1"/>        <xs:element ref="editors" minOccurs="0" maxOccurs="1"/>        <xs:element ref="journal" minOccurs="1" maxOccurs="1"/>        <xs:element ref="page" minOccurs="1" maxOccurs="1"/>      </xs:sequence>    </xs:complexType>  </xs:element>  <xs:element name="proceeding">    <xs:complexType>      <xs:sequence>        <xs:element ref="authors" minOccurs="1" maxOccurs="unbounded"/>        <xs:element ref="year" minOccurs="1" maxOccurs="1"/>        <xs:element ref="title" minOccurs="1" maxOccurs="1"/>        <xs:element ref="editors" minOccurs="0" maxOccurs="1"/>        <xs:element ref="journal" minOccurs="1" maxOccurs="1"/>        <xs:element ref="page" minOccurs="1" maxOccurs="1"/>      </xs:sequence>    </xs:complexType>  </xs:element>    <xs:element name="chapter">    <xs:complexType>      <xs:sequence>        <xs:element ref="authors" minOccurs="1" maxOccurs="unbounded"/>        <xs:element ref="year" minOccurs="1" maxOccurs="1"/>        <xs:element ref="title" minOccurs="1" maxOccurs="1"/>        <xs:element ref="book" minOccurs="1" maxOccurs="1"/>        <xs:element ref="page" minOccurs="0" maxOccurs="1"/>      </xs:sequence>    </xs:complexType>  </xs:element>    <xs:element name="books">    <xs:complexType>        <xs:element ref="book" minOccurs="0" maxOccurs="unbounded"/>    </xs:complexType>  </xs:element>    <xs:element name="journals">    <xs:complexType>        <xs:element ref="journalentry" minOccurs="0" maxOccurs="unbounded"/>    </xs:complexType>  </xs:element>    <xs:element name="chaptersAndProceedings">    <xs:complexType>        <xs:element ref="proceeding" minOccurs="0" maxOccurs="unbounded"/>        <xs:element ref="chapter" minOccurs="0" maxOccurs="unbounded"/>    </xs:complexType>  </xs:element>    <xs:element name="references">    <xs:complexType>      <xs:sequence>        <xs:element ref="books"/>        <xs:element ref="journals" minOccurs="0" maxOccurs="unbounded"/>        <xs:element ref="chaptersAndProceedings"/>      </xs:sequence>    </xs:complexType>  </xs:element></xs:schema>

Link to comment
Share on other sites

The "xs:complexType" cannot contain "xs:element"Try using:xs:annotation, xs:simpleCOntent, xs:group, xs:all, xs:choice, xs:sequence, xs:attribute, xs:attributeGroup, or xs:anyAttributeI'd recommend using xs:attribute - that should make it validate.edit: OH wait, you have more issues. use the xs:attribute whenever you are NOT using it inside a xs:sequence tag. The xs:element tag will work if it is nested inside a xs:sequence that is nested in a xs:complexType.I think that's all.arrgg, here is another - you are duplicating:<xs:element name="name" type="xs:string"/>at the opening of the document. Make the changes above and remove one of these and I think you are set.

Link to comment
Share on other sites

Hi Skemcin!Tnx a lot, the duplication error is now fixed :)I haven't been able to get the other error messages fixed...I've tried changing the <element> tags which were not in a <sequence> to <attribute> tags, but then I get the following error-message:---------------------Line File name: opdracht1-xsd.xml 38 Column: 74 Error: Attribute 'minOccurs' is not permitted to appear in element 'xs:attribute'.Attribute 'maxOccurs' is not permitted to appear in element 'xs:attribute'. Error Position: <xs:attribute ref="author" minOccurs="1" maxOccurs="unbounded"/>---------------------Can I use <xs:attribute ref="author"/> also for XML-files with this in it:<author name="MJ"/>So where author is an element, and not an attribute? That's the reason I used the <xs:element/>Also, I can't get all the <xs:element>s in a <sequence> tag, because I'd like my schema to be used with XML stuff like this:<chaptersAndProceedings> <chapter/> <chapter/> <proceeding/> <chapter/></chaptersAndProceedings>With multiple chapters and proceedings, in random order...I really don't know how to fix this. On the one hand I can't use <xs:element/> outside <xs:sequence>, on the other hand I don't want to use <xs:sequence>!Once again, thanks a lot in advance!:)M

Link to comment
Share on other sites

Oh and one more thing...I've tried this for <chaptersAndProceedings> and it didn't work :)( <xs:element name="chaptersAndProceedings"> <xs:complexType> <xs:all> <xs:element ref="proceeding" minOccurs="0" maxOccurs="unbounded"/> <xs:element ref="chapter" minOccurs="0" maxOccurs="unbounded"/> </xs:all> </xs:complexType> </xs:element>Errormessage:Line File name: opdracht1-xsd.xml 140 Column: 76 Error: Value 'unbounded' is not facet-valid with respect to enumeration '[0, 1]'. It must be a value from the enumeration.Value 'unbounded' of attribute 'maxOccurs' on element 'xs:element' is not valid with respect to its type, 'null'. Error Position: <xs:element ref="proceeding" minOccurs="0" maxOccurs="unbounded"/>I 'fixed' the other errors by just putting <sequence>-tags everywhere, but obviously I can't use that here... This is the only error-message left now, any ideas?GrM

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...