Professional Documents
Culture Documents
1ST DAMEL
Task 4
Markup language
DTD
AND
XML
SCH
EMA
1
1 A company uses XML files to inventory, among other things, printers. For each
printer you want to save its serial number, brand, model, weight, paper sizes it can work
with, the cartridge it uses, the type, the year of purchase and whether it is networked or
not.
<printers>
<printer numSerie="i245" type="laser" purchase="2010">
<brand>Epson</brand>.
<model>EPL300</model>.
<weight>4.52</weight>.
<size>A4</size>.
<size>A5</size>.
</cartridge>C-123BV</cartridge>.
<network/>
</printer>.
<printer numSerie="i246" type="dot matrix">
<brand>HP</brand>.
<model>LaserJet 2410</model>.
<weight>3.2</weight>.
<size>A4</size>.
</cartridge>C-456P</cartridge>.
</printer>.
</printers>
Write an XML Schema for these files, choosing the most appropriate data types and
taking into account that:
• The weight is a positive number and cannot have more than two decimal places.
• There may be more than one size.
• The type attribute can only take the values 'matrix', 'laser' and 'ink'. It is
mandatory.
• The numSeries attribute is mandatory and acts as an identifier.
• The cartridge consists of a capital C, a hyphen, three numbers and one or two
capital letters.
• All elements are mandatory, except enred.
• The enred element is optional. If present, it is an empty element.
• The purchase attribute, optional, stores the year of purchase. It is a positive
integer.
• Each file contains data for one or more printers.
2
XML SCHEMA
The parent element is <xs:schema> and must contain declarations for all elements
found in the xml.
In xml schema we have no way to define the root element in a special way, we
will indicate it with <xs:element name="root"> , which we will define as a
complex type if it has more elements inside and the xs:sequence tag to add the
different elements that form it and its restrictions. This way we will have a nested
xml schema.
Attributes must be declared after the sequence tag that defines the root elements.
<printer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Document1.xsd"> <!--link with relative path
to validate against the xsd-->
3
<brand>Epson</brand>.
<model>EPL300</model>.
<weight>4.52</weight>.
<size>A4</size>.
<size>A5</size>.
</cartridge>C-123BV</cartridge>.
<network/>
</printer>.
<brand>HP</brand>.
<model>LaserJet 2410</model>.
<weight>3.2</weight>.
<size>A4</size>.
</cartridge>C-456P</cartridge>.
</printer>.
</printers>
<xs:annotation>
<xs:documentation>
Define a list of printers.Pilar Alonso Suela.Task 04.1 DAMEL
</xs:documentation>
</xs:annotation>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="printers">
<xs:complexType>
<xs:sequence>
<!--here we reference the printer element, the references are a way to make
the xml schema more readable.there will be data for one or more printers-->
</xs:sequence>
</xs:complexType>
5
</xs:element>
<xs:element name="printer">
<xs:complexType>
<xs:sequence>
<!--the weight must be a positive number with no more than two decimal
places and must be declared within xs:restriction-->
<xs:minInclusive value="1"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string">
6
<xs:pattern value="[C][\-][0-9][0-9][0-9][A-Z]{1,2}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<!--attributes -->
<!--the serial number attribute must be mandatory and also serve as the
printer identifier-->>
<xs:simpleType>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<!--The type attribute must be mandatory and must only contain the values: dot
matrix, laser and ink-->.
<xs:enumeration value="laser"/>
<xs:enumeration value="ink"/>
</xs:restriction>
7
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
2.- An association of mus players uses XML files to store the information of the
tournaments it organizes. For each tournament you want to save the year it was held, the
previous winner (its id) and the participants' information. We would like to store the
participant's identifier, his/her partner's identifier, his/her full name, age, country and
also whether he/she is a seed or not.
<serialHead/>
</participant>.
<participant idP="j02" couple="j01">
<first name>Manuel Gómez</first name>.
<age>25</age>.
<country>Spain</country>.
</participant>.
<participant idP="j03" couple="j04">
<first name>Ana Puertas</first name>.
<age>22</age>.
<country> E5spain</country>.
<serialHead/>
</participant>.
<participant idP="j04" couple="j03">
<first name>Paco Fraile</first name>.
<age>45</age>.
<country>Spain</country>.
</participant>.
</tournament>.
Write an appropriate DTD for these files, keeping in mind that:
8
DTD
A DTD is a document with a .dtd extension and is responsible for ensuring that the XML
data complies with the constraints imposed in the dtd.
In this case I have declared it internally in the xml , but it is also possible to declare it
externally in the form of a plain text document with extension .dtd
Terminal elements (do not contain elements) are declared as follows: <!ELEMENT
data_type_name>.
TASK REQUIREMENTS
As the tournament must have participants we use > + to set a minimum of 1 or more in
the cardinality of the tournament element.
Within the participant element we will find that all contained elements must have at least
one occurrence (+) and that the element headOfSeries is optional so I use >?
Since idP must be an identifier >we will add ID to declare the attribute as an identifier.
9
The partner attribute must refer to the idP of another participant for this I will use
IDREF.
<!DOCTYPE tournament [
]>
<age>23</age>.
<country> Spain</country>.
<serialHead/>
</participant>.
<age>25</age>.
<country>Spain</country>.
</participant>.
<age>22</age>.
<country> E5spain</country>.
<serialHead/>
</participant>.
<age>45</age>.
<country>Spain</country>.
</participant>.
</tournament>.