XML schemas
Upcoming SlideShare
Loading in...5
×
 
  • 848 views

 

Statistics

Views

Total Views
848
Slideshare-icon Views on SlideShare
643
Embed Views
205

Actions

Likes
0
Downloads
20
Comments
0

3 Embeds 205

http://angel.spscc.edu 138
https://safefiles.instructure.com 62
http://www.ustudy.in 5

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

    XML schemas XML schemas Presentation Transcript

    • XML Schemas
      CIS-189
    • Alternative to DTD’s as way to define structure
      Defining a language (vocabulary)
      Structure may be also referred to as vocabulary
      Ensures that data matches specifications
      Serves as basis for other XML-related technologies
      XML Schemas
    • Use XML for definition
      Doesn’t have separate structure like DTD’s
      Schema must be well-formed
      Provides for built-in and user-defined data types
      Can be easily reused
      Supports concepts such as inheritance
      One object is based on another
      A definition may be reused and modified without starting from scratch each time
      Working with Schemas
    • Support World Wide Web Namespace recommendations
      A namespace allows the same name (data type/definition) to be used in different Schemas and properly understood
      A course may be defined as department, course number, title, credits and prerequisites for the College Catalog
      A course for grading may be defined as department, course number and credits for a grading application
      Using namespaces allows both definitions to be used, by specifying if working with a course defined for the catalog or grading
      Schemas and Namespaces
    • Schema file uses an .xsd extension
      Root element is the schema
      Can nest all elements within the schema
      Everything is hierarchical
      OR
      Can have multiple elements as child elements of the schema root
      Allows use of a definition any place in the document (data) file
      Elements which are child elements of schema are global
      Creating Schemas
    • Allows more specificity than DTD’s
      Can specify dates, numbers, ranges
      Datatypes fall into two categories:
      Simple deals with basic values
      Complex describes more intricate values or structures
      Schema Datatypes
    • Simple data type is about text, numbers, date
      Sometime referred to as “primitives”
      Data types built in to Schema vocabulary (and related elements, attributes) are in the XML Schema namespace
      Need reference to namespace to have valid XML specified (where to find the defined type)
      Elements that are Simple Datatypes don’t have attributes
      Including an attribute makes an element Complex
      Simple Datatypes
    • String
      Boolean
      Numbers
      Integer
      Decimal
      Float
      Double
      Custom (simpleType)
      Date/time
      Time
      TimeInstant
      Duration
      Date
      Month
      Year
      Century
      RecurringDate
      RecurringDay
      Simple Types
    • <?xml version=“1.0”?>
      <xsd:schemaxmlns:xsd=“http://www.w3.org/2001/XMLSchema”>
      <xsd:element name=“department” type=“xsd:string”/>
      <xsd:element name=“number” type=“xsd:string”/>
      <xsd:element name=“title” type=“xsd:string”/>
      <xsd:element name=“credits” type=“xsd:integer”/>
      </schema>
      Schema Defining a Course Using Simple Types
      xmlns:xsd= specifies where the namespace can be found
      xsd: specifies the namespace where the definition exists
      Assign attribute values to create the definition of an element in your vocabulary
    • The simpleType allows customization of base types
      Can create limits on values
      Specify ranges
      Specify lists
      Degrees is a simple type, based on string:
      <xsd:simpleType=“Degrees”>
      <xsd:restriction base=“xsd:string”>
      <xsd:enumeration value=“AA” />
      <xsd:enumeration value=“AS” />
      </xsd: restriction>
      </xsd:simpleType>
      Defining (Simple) Datatypes
    • Complex types allows combination of different elements and specification of order, new data types
      Can create an element Course which is comprised of simple types
      A valid Course must have department, number, title and credits elements in order:
      <xsd:element name=“course”>
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name=“department” type=“xsd:string”/>
      <xsd:element name=“number” type=“xsd:string”/>
      <xsd:element name=“title” type=“xsd:string”/>
      <xsd:element name=“credits” type=“xsd:integer”/>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      ComplexDatatypes
    • When using a schema, need to create a reference from data (.xml) file
      Use either the schemaLocation or noNamespaceSchemaLocation attribute of the root element
      <course xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceShemaLocation=“course.xsd”>
      Using a Schema
    • Creating a simple type
      A phone number is text, up to 20 characters
      <xs:simpleType name="PhoneSimpleType“>
      <xs:restrictionbase="xs:string“>
      <xs:maxLength value="20" />
      </xs:restriction>
      </xs:simpleType>
      Book Code – Employees.xsd
    • Using a simple type:
      The element homephone uses the simple type “PhoneSimpleType” to limit phone numbers to a maximum of 20 characters
      <xs:element name="homephone" type="PhoneSimpleType" />
      Book Code – Employees.xsd 2
    • Employees is a complex type made of employee, which uses the EmployeeType
      <xs:element name="employees“>
      <xs:complexType>
      <xs:sequence>
      <xs:element name="employee" type="EmployeeType" minOccurs="0" maxOccurs="unbounded" />
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      Book Code – Employees.xsd 3
    • Setting the root element for a schema
      <?xml version="1.0" encoding="utf-8"?>
      <xs:schemaattributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      Book Code – Employees.xsd 4
      xs becomes “shorthand” to refer to the Internet location for definitions; following element definitions all include that reference (xs)