SlideServe
Menu
Préférences
© SlideServe · v2026

Understanding X-Schema: The XML-Based Alternative to DTD

wesley-bates avatar
41 diapositives · 569 Views · Nov 27, 2014

X-Schema, or XML Schema Definition (XSD), is an XML-based alternative to Document Type Definitions (DTD). It describes the structure of XML documents by defining elements, attributes, child elements, and their sequences. X-Schema enhances data validation, supports rich data types, and allows for extensibility and reusability of schemas. Unlike DTDs, X-Schema is more powerful and can be easily edited, parsed, and transformed using XML tools such as XSLT. This guide provides insights into its benefits, structure, and practical examples.

Understanding X-Schema: The XML-Based Alternative to DTD - slide 1
01 / 41Understanding X-Schema: The XML-Based Alternative to DTD
1 / 17

Télécharger la présentation

Understanding X-Schema: The XML-Based Alternative to DTD
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. XML Technologies X-Schema

  2. What is X-Schema? (1) • XML-based alternative to DTD • Describes the structure of an XML document • Also referred to as XML Schema Definition (XSD)

  3. What is X-Schema? (2) • defines elements that can appear in a document • defines attributes that can appear in a document • defines which elements are child elements • defines the order of child elements • defines the number of child elements • defines whether an element is empty or can include text • defines data types for elements and attributes • defines default and fixed values for elements and attributes

  4. X-Schema vrs DTD • XML Schemas are extensible to future additions • XML Schemas are richer and more powerful than DTDs • XML Schemas are written in XML • XML Schemas support data types • XML Schemas support namespaces

  5. X-Schema makes it easy to • describe allowable document content • validate the correctness of data • work with data from a database • define restrictions on data • define data formats • convert data between different data types

  6. Why is it better to use an XML based schema? • We know the language • Can be edited with XML editors • Can be parsed with XML parsers • Can be manipulated with XML DOM • Can be transformed with XSLT

  7. Benefits of X-Schemas • Ensure secure data communication • 3/11/2004 is the 3rd of November or the 11th of March? • Can reuse schemas • Use one or many in the same document • Create own data types

  8. How to use X-Schema <?xml version="1.0"?> <note xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="note.xsd"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>

  9. The actual schema <?xml version="1.0"?> <xs:schema> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>

  10. <schema> element • Root element of any schema • May contain attributes • xmlns:xs="http://www.w3.org/2001/XMLSchema" • Indicate the XSchema namespace • targetNamespace="http://www.um.edu.mt" • Indicate that the elements defined (to, from, etc) come from the above namespace • xmlns="http://www.um.edu.mt" • Sets the default namespace • elementFormDefault="qualified“ • Qualified = all elements can be validated • Unqualified = only root element can be validated with the namespace

  11. Elements • A simple element contains only text • But it can have different types or restrictions (facets) • <xs:element name="xxx" type="yyy"/> • <xs:element name=“age" type=“xs:integer"/>

  12. Element Built-In Types • xs:string • xs:decimal • xs:integer • xs:boolean • xs:date • xs:time

  13. Default and Fixed types <xs:element name="color" type="xs:string" default="red"/> <xs:element name="color" type="xs:string" fixed="red"/>

  14. Attributes • Simple elements cannot have attributes • Only complex elements have attributes • An attribute is declared as a simple type <xs:attribute name="xxx" type="yyy"/>

  15. Default, Fixed and Optional attributes <xs:attribute name="lang" type="xs:string" default="EN"/> <xs:attribute name="lang" type="xs:string" fixed="EN"/> <xs:attribute name="lang" type="xs:string" use="required"/> * Optional by default (unless specified)

  16. Restrictions (Facets) - Range <xs:element name="age"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> <xs:maxInclusive value="120"/> </xs:restriction> </xs:simpleType> </xs:element>

  17. Restrictions (Facets) – Set 1 <xs:element name="car"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Audi"/> <xs:enumeration value="Golf"/> <xs:enumeration value="BMW"/> </xs:restriction> </xs:simpleType> </xs:element>

  18. Restrictions (Facets) – Set 2 <xs:element name="car" type="cType"/> <xs:simpleType name="cType"> <xs:restriction base="xs:string"> <xs:enumeration value="Audi"/> <xs:enumeration value="Golf"/> <xs:enumeration value="BMW"/> </xs:restriction> </xs:simpleType>

  19. Restrictions (Facets) - Pattern <xs:element name="letter"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[a-z]"/> </xs:restriction> </xs:simpleType> </xs:element>

  20. Restrictions (Facets) - Patterns Regular expressions example [A-Z] any letter uppercase [A-Z][A-Z] two letters uppercase [a-zA-Z] any letter any case [xyz] x or y or z [0-9] any number one digit ([A-Z])+ one or more ([A-Z])* zero or more male|female either or [a-zA-Z]{8} exactly 8 characters

  21. Restricting white space (1) <xs:element name="address"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:whiteSpace value="preserve"/> </xs:restriction> </xs:simpleType> </xs:element>

  22. Restricting white space (2) • Value can be • Preserve • Do not remove white space • Replace • Replace line feeds, tabs, spaces, and carriage returns with spaces • Collapse • Same as replace but collapse multiple spaces into one

  23. Restrictions (Facets) - Length <xs:element name="password"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="5"/> <xs:maxLength value="8"/> </xs:restriction> </xs:simpleType> </xs:element>

  24. Summarising Restrictions

  25. Complex Elements • empty elements • elements that contain only other elements • elements that contain only text • elements that contain both other elements and text

  26. Complex Empty Elements <xs:element name="product"> <xs:complexType> <xs:attribute name="prodid" type="xs:positiveInteger"/> </xs:complexType> </xs:element> Ex <product prodid="1345" />

  27. Complex Elements Only • Contains only other elements <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>

  28. Complex Elements Only Ex <person> <firstname>John</firstname> <lastname>Smith</lastname> </person>

  29. Complex TextOnly Element <xs:element name="shoesize"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:integer"> <xs:attribute name="country" type="xs:string" /> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> Eg <shoesize country="france">35</shoesize>

  30. Complex Mixed Content <xs:element name="letter"> <xs:complexType mixed="true"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="orderid" type="xs:positiveInteger"/> <xs:element name="shipdate" type="xs:date"/> </xs:sequence> </xs:complexType> </xs:element>

  31. 7 Indicators • Order indicators: • All • All must occur but in any order • Choice • Either or can occur • Sequence • Must appear in a specified sequence • Occurrence indicators: • maxOccurs • minOccurs • Group indicators: Group elements or attributes together and allow for reuse • Group name • attributeGroup name

  32. All, Choice, Sequence indicator <xs:element name="person"> <xs:complexType> <xs:all> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:all> </xs:complexType> </xs:element>

  33. Occurrence indicator <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="child_name" type="xs:string" maxOccurs="10" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element>

  34. <any> and <anyAttribute> <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="child_name" type="xs:string" maxOccurs="10" minOccurs="0"/> <xs:any minOccurs="0"/> </xs:sequence> <xs:anyAttribute/> </xs:complexType> </xs:element> *allows for any element or attribute but it has to be defined just the same in another XSchema

  35. Substitutions <xs:element name="name" type="xs:string"/> <xs:element name=“isem" substitutionGroup="name"/> Allows for … <customer> <isem>John</isem> </customer>

  36. String Datatype

  37. Date Datatype

  38. Numeric Datatype

  39. Example

  40. Exercise • Define an XML Vocabulary for a Toaster Markup Language (TML) using XSchema • It must support features such as: • Print message on toast • Display on LCD • Time stamp

  41. Questions?