Jump to content

Help debugging Schema

Recommended Posts

Does anyone see problems here, because it doesn't work:

<?xml version="1.0" encoding="utf-8" ?><!-- BookCollectionML 1.0 XML Schema --><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:complexType>	<xs:element name="library" type="xs:string">		<xs:attribute name="version" type="xs:string" use="required" fixed="1.0" />				<xs:element name="book" type="xs:string">			<xs:complexType>				<xs:element name="title" type="xs:string">					<xs:attribute name="alternate" type="xs:boolean" />				</xs:element>			</xs:complexType>			<xs:element name="series" type="xs:string" />			<xs:element name="author" type="xs:string" />			<xs:element name="pages" type="xs:positiveInteger" />			<xs:element name="edition" type="xs:string" />			<xs:complexType>				<xs:element name="isbn" type="xs:string">					<xs:attribute name="type" type="xs:string">						<xs:restriction base="xs:string">							<xs:enumeration value="isbn-10" />							<xs:enumeration value="isbn-13" />						</xs:restriction>					</xs:attribute>				</xs:element>			</xs:complexType>			<xs:element name="picture" type="xs:anyURI" />			<xs:element name="notes" type="xs:string" />		</xs:element>				<xs:element name="music" type="xs:string">			<xs:element name="album" type="xs:string" />			<xs:element name="artist" type="xs:string" />			<xs:element name="media" type="xs:string" />			<xs:element name="label" type="xs:string" />			<xs:element name="cdp" type="xs:string" />			<xs:complexType>			<xs:element name="songlist" type="xs:string">				<xs:element name="song" type="xs:string">					<xs:attribute name="track" type="xs:integer" />				</xs:element>			</xs:element>			</xs:complexType>			<xs:element name="picture" type="xs:anyURI" />			<xs:element name="notes" type="xs:string" />		</xs:element>				<xs:element name="publication" type="xs:string">			<xs:element name="name" type="xs:string" />			<xs:element name="type" type="xs:string" />			<xs:element name="topic" type="xs:string" />			<xs:element name="issue" type="xs:string">				<xs:element name="pubDate" type="xs:string" />				<xs:element name="topic" type="xs:string" />				<xs:element name="picture" type="xs:anyURI" />				<xs:element name="notes" type="xs:string" />			</xs:element>			<xs:element name="notes" type="xs:string" />		</xs:element>				<xs:element name="movie" type="xs:string">			<xs:element name="title" type="xs:string" />			<xs:element name="director" type="xs:string" />			<xs:element name="producer" type="xs:string" />			<xs:element name="actor" type="xs:string">				<xs:element name="name" type="xs:string" />				<xs:element name="role" type="xs:string" />				<xs:element name="character" type="xs:string" />			</xs:element>		</xs:element>			</xs:element></xs:complexType></xs:schema>

Link to post
Share on other sites

Oh man... you have schema totally wrong. Unfortunatly, schema is just not that intuitive as you've made it.The contents of every element, whether it's attributes, child elements or text, needs to be declared with a type. Saying 'type="xs:string"' is not enough. This only attaches a premade type to the element, which in this case is a simple string. If you specify that to an element, it means it can't hold any attributes, or data that's not a string. In order to attach a type on the spot, you need to have "xs:complexType" as the first child element of "xs:element".Attributes are not declared before all child elements, they are declared after the "xs:complexType" definition.When you list the child elements an element can have, they must be grouped in either "xs:all", "xs:sequence", or "xs:choise". In your case, I suppose you need "xs:all" pretty much everywhere.When an element is supposed to be allowed to have both child nodes (whether it's just attributes or elements too), and text, its xs:complexType must have 'mixed="true"'.Here's a Schema that adresses theese issues, and is valid on its own. Whether it's exactly what you need, I can't say. You'll have to tweak it yourself, following the rules outlined above:

<?xml version="1.0" encoding="utf-8"?><!-- BookCollectionML 1.0 XML Schema --><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">	<xs:element name="library" type="xs:string">		<xs:complexType>			<xs:all>				<xs:element name="book" type="xs:string">					<xs:complexType>						<xs:all>							<xs:element name="title" type="xs:string">								<xs:complexType>									<xs:attribute name="alternate" type="xs:boolean"/>								</xs:complexType>							</xs:element>							<xs:element name="series" type="xs:string"/>							<xs:element name="author" type="xs:string"/>							<xs:element name="pages" type="xs:positiveInteger"/>							<xs:element name="edition" type="xs:string"/>							<xs:element name="isbn">								<xs:complexType mixed="true">									<xs:attribute name="type">										<xs:simpleType>											<xs:restriction base="xs:string">												<xs:enumeration value="isbn-10"/>												<xs:enumeration value="isbn-13"/>											</xs:restriction>										</xs:simpleType>									</xs:attribute>								</xs:complexType>							</xs:element>							<xs:element name="picture" type="xs:anyURI"/>							<xs:element name="notes" type="xs:string"/>						</xs:all>					</xs:complexType>				</xs:element>				<xs:element name="music" type="xs:string">					<xs:complexType>						<xs:all>							<xs:element name="album" type="xs:string"/>							<xs:element name="artist" type="xs:string"/>							<xs:element name="media" type="xs:string"/>							<xs:element name="label" type="xs:string"/>							<xs:element name="cdp" type="xs:string"/>							<xs:element name="songlist">								<xs:complexType>									<xs:all>										<xs:element name="song" type="xs:string">											<xs:complexType mixed="true">												<xs:attribute name="track" type="xs:integer"/>											</xs:complexType>										</xs:element>									</xs:all>								</xs:complexType>							</xs:element>							<xs:element name="picture" type="xs:anyURI"/>							<xs:element name="notes" type="xs:string"/>						</xs:all>					</xs:complexType>				</xs:element>				<xs:element name="publication">					<xs:complexType>						<xs:all>							<xs:element name="name" type="xs:string"/>							<xs:element name="type" type="xs:string"/>							<xs:element name="topic" type="xs:string"/>							<xs:element name="issue">								<xs:complexType>									<xs:all>										<xs:element name="pubDate" type="xs:string"/>										<xs:element name="topic" type="xs:string"/>										<xs:element name="picture" type="xs:anyURI"/>										<xs:element name="notes" type="xs:string"/>									</xs:all>								</xs:complexType>							</xs:element>							<xs:element name="notes" type="xs:string"/>						</xs:all>					</xs:complexType>				</xs:element>				<xs:element name="movie">					<xs:complexType>						<xs:all>							<xs:element name="title" type="xs:string"/>							<xs:element name="director" type="xs:string"/>							<xs:element name="producer" type="xs:string"/>							<xs:element name="actor">								<xs:complexType>									<xs:all>										<xs:element name="name" type="xs:string"/>										<xs:element name="role" type="xs:string"/>										<xs:element name="character" type="xs:string"/>									</xs:all>								</xs:complexType>							</xs:element>						</xs:all>					</xs:complexType>				</xs:element>			</xs:all>			<xs:attribute name="version" type="xs:string" use="required" fixed="1.0"/>		</xs:complexType>	</xs:element></xs:schema>

You should get a good Schema editor btw. I use StylusStudio, and that's pretty much how I do all of my Schema editing.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...