Jump to content

Schema Using Empty Xml Elements


odinpeeg

Recommended Posts

Hello all, I've been using the w3schools website to try and complete a piece of work which requires me to produce an XML file to store information and an XML Schema to validate it against. At the moment I'm having difficulty validating the part of it XML against the schema using this site:http://tools.decisionsoft.com/schemaValidate/ which will validate the schema and then the file against the schema.My XML file consists of (with more player elements):<dartsteam> <player> <firstname>Dan</firstname> <clubmoniker>Million Dollar Shot</clubmoniker> <lastname>Robins</lastname> <email>danrobins@hotmail.com</email><!--Speechamrks are not required around the quote--> <playerpic filename="images/lankydan.jpg"/> <walkintune> <artist>Kelis</artist> <track>Millionaire</track> </walkintune> <favouritequote quoteby="Fran Cotton">They used to say it was Loughborough arrogance but we prefer to call it a self beleif in our own skills and abilities.</favouritequote> <bringstoclub>As president I feel I bring security and stability to the club, plus with out me there would be no club as I founded it with Mr. Cummins</bringstoclub> <recentform> <tournamentposition placed="R1"/> <tournamentposition placed="QF"/> <tournamentposition placed="RU"/> </recentform> </player></dartsteam>The issue I am having is with the <recentform> tag as it is the parent of 3 empty elements. My schema is below and I do not know where I'm going wrong.<?xml version="1.0" encoding="ISO-8859-1" ?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><!--define the complextype for the player picture--><xs:complexType name="image"> <xs:attribute name="filename" type="xs:string"/></xs:complexType><!--defines the complex type used for the walk in tune--><xs:complexType name="trackinfo"> <xs:sequence> <xs:element name="artist" type="xs:string"/> <xs:element name="track" type="xs:string"/> </xs:sequence></xs:complexType><!--defines the complex type used for the favourite quote--><xs:complexType name="quote"> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="quoteby" type="xs:string"/> </xs:extension> </xs:simpleContent></xs:complexType><!--defines the enumerations for the allowed tournament places--><xs:simpleType name="tournamentplaceenum"> <xs:restriction base="xs:string"> <xs:enumeration value="W"/> <!--winner--> <xs:enumeration value="RU"/> <!--runner up--> <xs:enumeration value="SF"/> <!--semi final--> <xs:enumeration value="QF"/> <!--Quarter final--> <xs:enumeration value="R1"/> <!--first round only--> </xs:restriction></xs:simpleType> <!--defines the type used to list the club tournament positiions--><!--(empty element so only specify attribute)--><xs:complexType name="tournamentplace"> <xs:attribute name="placed" type="tournamentplaceenum"/></xs:complexType><!--defines the list as a complex type--><xs:complexType name="tournamentplacelist"><xs:sequence><xs:element name="tournamentposition" type="tournamentplace"/></xs:sequence></xs:complexType><!--defines compelx type for the player record, which will reference the other complex types--><xs:complexType name="playerrecord"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="clubmoniker" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:element name="email" type="xs:string" /> <xs:element name="playerpic" type="image" /> <!--references complex type--> <xs:element name="walkintune" type="trackinfo"/> <!--references complex type--> <xs:element name="favouritequote" type="quote"/> <!--reference complex type--> <xs:element name="bringstoclub" type="xs:string" /> <xs:element name="recentform" type="tournamentplacelist"/> <!--references complex type--> </xs:sequence></xs:complexType><!--define the type for the root element of the XML document--><xs:complexType name="dartsclub"> <xs:sequence> <xs:element name="player" type="playerrecord"/> <!--reference complex type--> </xs:sequence></xs:complexType><!--just one instance of the XML root document node--><xs:element name="dartsteam" type="dartsclub"/> <!--class complex type def of dart team--></xs:schema>How should I be setting the schema to stop the errors in validation? The schema for empty elements confuses me somewhat ..Thanks for any help anybodyTom

Link to comment
Share on other sites

Are there any exact error messages being outputted? I don't see anything wrong with that schema at a first glance... I have to say, you've taken a somewhat different approach than what I'm used to (you declare all types, and only one element, with each element's child nodes being described in its type - I usually declare all nodes, with each one's type describing its possible childs), but that isn't the problem here.

Link to comment
Share on other sites

Are there any exact error messages being outputted? I don't see anything wrong with that schema at a first glance... I have to say, you've taken a somewhat different approach than what I'm used to (you declare all types, and only one element, with each element's child nodes being described in its type - I usually declare all nodes, with each one's type describing its possible childs), but that isn't the problem here.
I get the following two errors, one recurs for each player element and one appears just the once.Validation 47, 37 cvc-complex-type.2.4.d: Invalid content was found starting with element 'tournamentposition'. No child element is expected at this point.Validation 51, 10 cvc-complex-type.2.4.d: Invalid content was found starting with element 'player'. No child element is expected at this point.Validation 65, 37 cvc-complex-type.2.4.d: Invalid content was found starting with element 'tournamentposition'. No child element is expected at this point.Validation 83, 37 cvc-complex-type.2.4.d: Invalid content was found starting with element 'tournamentposition'. No child element is expected at this point.(repeats same error. . . . Validation x,37)CheersTOm
Link to comment
Share on other sites

I get the following two errors, one recurs for each player element and one appears just the once.Validation 47, 37 cvc-complex-type.2.4.d: Invalid content was found starting with element 'tournamentposition'. No child element is expected at this point.Validation 51, 10 cvc-complex-type.2.4.d: Invalid content was found starting with element 'player'. No child element is expected at this point.Validation 65, 37 cvc-complex-type.2.4.d: Invalid content was found starting with element 'tournamentposition'. No child element is expected at this point.Validation 83, 37 cvc-complex-type.2.4.d: Invalid content was found starting with element 'tournamentposition'. No child element is expected at this point.(repeats same error. . . . Validation x,37)CheersTom
HELP!!!
Link to comment
Share on other sites

I finally tool it to my "lab" (Stylus Studio really), and after a bit of investigation (generated a valid XML according to the Schema, then gradually tweaking it until it becomes like yours, seeing what errors crop along the way), it seems you haven't specified maxOccurs anywhere. You have multiple "tournamentposition" in "recentform". The content model of "recentform" doesn't say any minOccurs or maxOccurs, which means there must be one and only one instance of that element at that point. The simple fix is to simply declare maxOccurs as "unbounded". I've also declared the "player" element as such, since there will be more elements from it.Your schema after the changes:

<?xml version="1.0" encoding="ISO-8859-1"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">	<!--define the complexType for the player picture-->	<xs:complexType name="image">		<xs:attribute name="filename" type="xs:string"/>	</xs:complexType>	<!--defines the complex type used for the walk in tune-->	<xs:complexType name="trackinfo">		<xs:sequence>			<xs:element name="artist" type="xs:string"/>			<xs:element name="track" type="xs:string"/>		</xs:sequence>	</xs:complexType>	<!--defines the complex type used for the favorite quote-->	<xs:complexType name="quote">		<xs:simpleContent>			<xs:extension base="xs:string">				<xs:attribute name="quoteby" type="xs:string"/>			</xs:extension>		</xs:simpleContent>	</xs:complexType>	<!--defines the enumerations for the allowed tournament places-->	<xs:simpleType name="tournamentplaceenum">		<xs:restriction base="xs:string">			<xs:enumeration value="W"/>			<!--winner-->			<xs:enumeration value="RU"/>			<!--runner up-->			<xs:enumeration value="SF"/>			<!--semi final-->			<xs:enumeration value="QF"/>			<!--Quarter final-->			<xs:enumeration value="R1"/>			<!--first round only-->		</xs:restriction>	</xs:simpleType>	<!--defines the type used to list the club tournament positions-->	<!--(empty element so only specify attribute)-->	<xs:complexType name="tournamentplace">		<xs:attribute name="placed" type="tournamentplaceenum"/>	</xs:complexType>	<!--defines the list as a complex type-->	<xs:complexType name="tournamentplacelist">		<xs:sequence>			<xs:element name="tournamentposition" type="tournamentplace" maxOccurs="unbounded"/>		</xs:sequence>	</xs:complexType>	<!--defines complex type for the player record, which will reference the other complex types-->	<xs:complexType name="playerrecord">		<xs:sequence>			<xs:element name="firstname" type="xs:string"/>			<xs:element name="clubmoniker" type="xs:string"/>			<xs:element name="lastname" type="xs:string"/>			<xs:element name="email" type="xs:string"/>			<xs:element name="playerpic" type="image"/>			<!--references complex type-->			<xs:element name="walkintune" type="trackinfo"/>			<!--references complex type-->			<xs:element name="favouritequote" type="quote"/>			<!--reference complex type-->			<xs:element name="bringstoclub" type="xs:string"/>			<xs:element name="recentform" type="tournamentplacelist"/>			<!--references complex type-->		</xs:sequence>	</xs:complexType>	<!--define the type for the root element of the XML document-->	<xs:complexType name="dartsclub">		<xs:sequence>			<xs:element name="player" type="playerrecord" maxOccurs="unbounded"/>			<!--reference complex type-->		</xs:sequence>	</xs:complexType>	<!--just one instance of the XML root document node-->	<xs:element name="dartsteam" type="dartsclub"/>	<!--class complex type def of dart team--></xs:schema>

Link to comment
Share on other sites

  • 7 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...