Simple XML schema :)

Associate
Joined
30 Sep 2004
Posts
2,301
Location
City of Rain
hello guys, I need some help here :p

The question:

Write an XML Schema equivalent to the following XML DTD (note:
xmlns:xsd="http://www.w3.org/2001/XMLSchema"):

Code:
<!ELEMENT book (title, chapter+)>
<!ATTLIST book
         type (fiction | non-fiction) #REQUIRED>
<!ELEMENT chapter (title, paragraph+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT paragraph (#PCDATA)>

My answer:

Code:
<?xml version ="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	    targetNamespace="http://www.books.org"
	    xmlns="http://www.books.org"
	    elementFormDefault="qualified">
 <xsd:element name="book">
   <xsd:complexType>
     <xsd:sequence>
        <xsd:element ref="title" minOccurs="1" maxOccurs="1"/>
        <xsd:element ref="chapter" minOccurs="1" maxOccurs="unbounded"/>
     </xsd:sequence>
     <xsd:attribute name="type" use="required">
        <xsd:simpleType>	
	 <xsd:restriction base="xsd:string">
            <xsd:enumeration value="fiction"/>
	    <xsd:enumeration value="non-fiction"/>   	
	 </xsd:restriction>
        </xsd:simpleType>
     </xsd:attribute>	
   </xsd:complexType>
 </xsd:element>
 
 <xsd:element name="chapter">
	<xsd:complexType>
	  <xsd:sequence>
	    <xsd:element ref="title"     minOccurs="1" maxOccurs="1"/>
	    <xsd:element ref="paragraph" minOccurs="1" maxOccurs="unbounded"/>
	  </xsd:sequence>
	</xsd:complexType>  
 </xsd:element>
 <xsd:element name="title" type="xsd:string"/>
 <xsd:element name="paragraph" type="xsd:string"/>
</xsd:schema>

is it correct?

cheers :cool:
 
Last edited:
@RobH: do you know any website that let me "compare" the DTD/Schema and sample XML data to see if they "match up"?

@Yeggstry: cheers:D its just a question from the pastpaper. Im revising for my exam on Monday :p
 
Cool :) I'd imagine that even if you do make a mistake on the actual exam you'd probably only drop one or two points (assuming its a 5-10 point question I guess).

actually its just a 3 mark question :eek: but every point counts in the exam so I need to make sure I do it correctly :p
 
Back
Top Bottom