Schema
Upcoming SlideShare
Loading in...5
×
 

Schema

on

  • 1,363 views

XML SCHEMA OVERVIEW

XML SCHEMA OVERVIEW

Statistics

Views

Total Views
1,363
Slideshare-icon Views on SlideShare
1,363
Embed Views
0

Actions

Likes
1
Downloads
47
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Schema Schema Presentation Transcript

    • SCHEMA OVERVIEW e-logistics 2009 Eduard Rodés Gubern Port de Barcelona
    • Purpose of XML Schemas
      • Specify:
        • the structure of instance documents
          • “ this element contains these elements, which contains these other elements, etc"
        • the datatype of each element/attribute
          • "this element shall hold an integer with the range 0 to 12,000" (DTDs don't do too well with specifying datatypes like this)
        • XML Schema is an XML-based language used to create XML-based languages and data models. An XML schema defines element and attribute names for a class of XML documents. The schema also specifies the structure that those documents must adhere to and the type of content that each element can hold.
        • XML documents that attempt to adhere to an XML schema are said to be instances of that schema. If they correctly adhere to the schema, then they are valid instances.
    • A First Look
      • An XML schema describes the structure of an XML instance document by defining what each element must or may contain. An element is limited by its type.
    • what each element contains
      • Elements can be of simple type or complex type.
      • Simple type elements can only contain text. They can not have child elements or attributes.
      • All the built-in types are simple types (e.g, xs:string).
      • Schema authors can derive simple types by restricting another simple type. For example, an email type could be derived by limiting a string to a specific pattern.
      • Simple types can be atomic (e.g, strings and integers) or non-atomic (e.g, lists).
      • Complex-type elements can contain child elements and attributes as well as text.
      • By default, complex-type elements have complex content, meaning that they have child elements.
      • Complex-type elements can be limited to having simple content, meaning they only contain text. They are different from simple type elements in that they have attributes.
      • Complex types can be limited to having no content, meaning they are empty, but they have may have attributes.
      • Complex types may have mixed content - a combination of text and child elements.
    • Schema – friend.xsd
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema“
      • targetNamespace=&quot;http://www.galactinav.com&quot;
      • xmlns=&quot;http://www.galactinav.com&quot;
      • elementFormDefault=&quot;qualified&quot;>
      • <xsd:element name=&quot;friend&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element ref=&quot;name&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;1&quot;/>
      • <xsd:element ref=&quot;address&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;unbounded&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • <xsd:element name=&quot;address&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element ref=&quot;street&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;1&quot;/>
      • <xsd:element ref=&quot;city&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;1&quot;/>
      • <xsd:element ref=&quot;country&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;1&quot;/>
      • <xsd:element ref=&quot;zip&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;1&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • <xsd:element name=&quot;name&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;street&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;city&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;country&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;zip&quot; type=&quot;xsd:string&quot;/>
      • </xsd:schema>
      • <!ELEMENT friend (name, address+)>
      • <!ELEMENT name (#PCDATA)>
      • <!ELEMENT address (street, city, country, zip)>
      • <!ELEMENT street (#PCDATA)>
      • <!ELEMENT city (#PCDATA)>
      • <!ELEMENT country (#PCDATA)>
      • <!ELEMENT zip (#PCDATA)>
    • ATTLIST ELEMENT ID #PCDATA NMTOKEN ENTITY CDATA friend name zip address country city street This is the vocabulary that DTDs provide to define your new vocabulary (Source:Roger L. Costello)
    • element complexType schema sequence http://www.w3.org/2001/XMLSchema string integer boolean This is the vocabulary that XML Schemas provide to define your new vocabulary One difference between XML Schemas and DTDs is that the XML Schema vocabulary is associated with a name (namespace). Likewise, the new vocabulary that you define must be associated with a name (namespace). With DTDs neither set of vocabulary is associated with a name (namespace) [because DTDs pre-dated namespaces]. friend name zip address country city street http://www.galactinav.com ( targetNamespace ) (Source:Roger L. Costello)
    • XML instance document
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <friend xmlns=&quot;http://www.galactinav.com&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://www.galactinav.com friend.xsd&quot;>
      • <name>El Soussy</name>
      • <address>
      • <street>Palestinian Gardens</street>
      • <city>Alexandria</city>
      • <country>EG</country>
      • <zip>90210</zip>
      • </address>
      • </friend>
      If you want to validate the files http://tools.decisionsoft.com/schemaValidate / Or download xmlspy www.altova.com
    • Referencing a schema in an XML instance document BookStore.xml BookStore.xsd targetNamespace=&quot;http://www.books.org&quot; schemaLocation=&quot;http://www.books.org BookStore.xsd&quot; - defines elements in namespace http://www.books.org - uses elements from namespace http://www.books.org A schema defines a new vocabulary. Instance documents use that new vocabulary. (Source:Roger L. Costello)
    • Note multiple levels of checking BookStore.xml BookStore.xsd XMLSchema.xsd (schema-for-schemas) Validate that the xml document conforms to the rules described in BookStore.xsd Validate that BookStore.xsd is a valid schema document, i.e., it conforms to the rules described in the schema-for-schemas (Source:Roger L. Costello)
    • Default Value for minOccurs and maxOccurs
      • The default value for minOccurs is &quot;1&quot;
      • The default value for maxOccurs is &quot;1&quot;
      <xsd:element ref=&quot;Title&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;1&quot;/> <xsd:element ref=&quot;Title&quot;/> Equivalent! (Source:Roger L. Costello)
    • Named Types <?xml version=&quot;1.0&quot;?> <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; targetNamespace=&quot;http://www.galactinav.com&quot; xmlns=&quot;http://www.galactinav.org&quot; elementFormDefault=&quot;qualified&quot;> <xsd:element name=“addressbook&quot;> <xsd:complexType> <xsd:sequence> <xsd:element name=“ friend &quot; maxOccurs=&quot;unbounded&quot;/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name=&quot;friend“> <xsd:complexType> <xsd:sequence> <xsd:element name=“name”/> <xsd:element name=“address&quot; type=“addressdata” maxOccurs=&quot;unbounded&quot;/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:complexType name=“addressdata” > <xsd:sequence> <xsd:element name=&quot;street&quot; type=“string”/> <xsd:element name=&quot;city&quot; type=“string”/> <xsd:element name=&quot;country&quot; type=“string”/> <xsd:element name=&quot;zip&quot; type=“string”/> </xsd:sequence> </xsd:complexType> </xsd:schema> The advantage of splitting out friend's element declarations and wrapping them in a named type is that now this type can be reused by other elements. Named type
    • Built-in datatypes (Source:W3C Recomendation)
    • Built-in datatypes Primitive Note: 'T' is the date/time separator INF = infinity NAN = not-a-number a NOTATION from the XML spec NOTATION a namespace qualified name QName http://www.xfront.com anyURI a base64 string base64Binary a hex string hexBinary format: --MM-- gMonth format: ---DD (note the 3 dashes) gDay format: --MM-DD gMonthDay format: CCYY gYear format: CCYY-MM gYearMonth format: CCYY-MM-DD date format: hh:mm:ss.sss time format: CCYY-MM-DDThh-mm-ss dateTime P1Y2M3DT10H30M12.3S duration 12.56E3, 12, 12560, 0, -0, INF, -INF, NAN double 12.56E3, 12, 12560, 0, -0, INF, -INF, NAN float 7.08 decimal {true, false} boolean &quot;Hello World&quot; string
    • Built-in datatypes Derived 1 to infinity positiveInteger 0 to 255 unsignedByte 0 to 65535 unsignedShort 0 to 4294967295 unsignedInt 0 to 18446744073709551615 unsignedLong 0 to infinity nonNegativeInteger -127 to 128 byte -32768 to 32767 short -2147483648 to 2147483647 int -9223372036854775808 to 9223372036854775808 long negative infinity to -1 negativeInteger negative infinity to 0 nonPositiveInteger 456 integer must be used only with attributes ENTITY must be used only with attributes IDREF must be used only with attributes ID part (no namespace qualifier) NCName   Name must be used only with attributes NMTOKENS must be used only with attributes NMTOKEN must be used only with attributes ENTITIES must be used only with attributes IDREFS any valid xml:lang value, e.g., EN, FR, ... language String w/o tabs, l/f, leading/trailing spaces, consecutive spaces token A string without tabs, line feeds, or carriage returns normalizedString
    • Attributes
      • We take the html img attributes
      • <ATTLIST img
        • src CDATA #REQUIRED
        • alt CDATA #REQUIRED
        • height CDATA #IMPLIED
        • width CDATA #IMPLIED>
      <xs:element name=&quot;img&quot;> <xs:complexType> <xs:attributeGroup ref=&quot;attrs&quot;/> <xs:attribute name=&quot;src&quot; use=&quot;required&quot; type=&quot;URI&quot;/> <xs:attribute name=&quot;alt&quot; use=&quot;required&quot; type=&quot;Text&quot;/> <xs:attribute name=&quot;height&quot; type=&quot;Length&quot;/> <xs:attribute name=&quot;width&quot; type=&quot;Length&quot;/> </xs:complexType> </xs:element>