• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blogspot.com

Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blogspot.com







Total Views
Views on SlideShare
Embed Views



2 Embeds 35

http://www.slideshare.net 33
http://pinterest.com 2



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.

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

    Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blogspot.com Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blogspot.com Presentation Transcript

    • XML For Dummies
      Book Author : Lucinda Dykes & Ed Tittle
      Slides Prepared By: Son TN
      Chapter 10 :Building a Custom XML Schema
    • Contents
      Doing the Validity Rag
      Step 1: Understanding Your Data
      Step 2: Being the Root of All Structure: Elements
      Step 3: Building Content Models
      Step 4: Using Attributes to Shed Light on Data Structure
      Step 5: Using Datatype Declarations to Define What’s What
      Tricks of the Trade
      Creating a Simple Schema
      Using a Schema with an XML File in Word 2003
    • 10.1 Doing the Validity Rag
      An XML document is valid if it conforms to the rules you define in your schema.
      Validation against a schema is very useful if your XML documents contain a lot of data content that needs to be formatted in a particular way.
      Building a simple XML Schema requires these steps:
      Understand your data.
      Create element declarations.
      Define content models.
      Create attribute declarations.
      Add datatype declarations.
      This chapter takes you through the entire process of creating a custom schema that perfectly suits your XML document’s every need.
    • 10.2 Step 1: Understanding Your Data
      Before building a custom schema :
      Understand the basic nature and function of your data.
      Take some time to look at the kind(s) of data you’ll be using in your XML documents
      Example :
      Is your data a collection of book titles, author names, and publishers?
      Before you design your schema :
      Need to be clear about what you want to do with the data.
      Example :
      Do you want to export data to a database from your XML documents, or do you want it available for access from wireless devices?
    • 10.3 Step 2: Being the Root of All Structure: Elements
      Elements define the basic structure for any XML document, including those created according to a schema.
      After you’ve got a good handle on your data and are ready to build a schema that fits it :
      You should first decide which elements will be included in your XML document.
      As a first step in declaring the elements for your schema, map out the basic structure of the document:
      What elements do you think you’ll need?
      How do they fit together?
      • A map makes deciding what kind of attributes, content models, and datatypes you need to define a lot easier.
      • Identifying the underlying structure of an XML document makes building your schema a lot easier.
    • 10.4 Step 3: Building Content Models
      A content model defines the type of content that can be contained in an element.
      The four content models for XML Schema elements is :
      Complex type definitions can include compositor elements, which specify order and occurrence restraints. The three compositors included in the XML Schema language are as follows:
    • 10.4 Step 3: Building Content Models (Cont)
      First, create a complex type definition for the books element.
      <xsd:element name=”books”>
      <xsd:element name=”book” type=”bookType”/>
      The books element in this
      case contains all the other elements in the schema document except for
      the schema element.
      A sequence includes one or more element references.
    • 10.4 Step 3: Building Content Models (Cont)
      When you use a sequence compositor, you specify child elements in one of two ways:
      By using a ref attribute with a value equal to the value of the name attribute in each child element’s element declaration.
      By using a name attribute with a value equal to the value of the child element’s name along with a type attribute with the value of a user-defined complex type
      <xsd:element ref=”title”/>
      <xsd:element name=”title”/>
      <xsd:element name=”book” type=”bookType”/>
    • 10.5 Step 4: Using Attributes to ShedLight on Data Structure
      Attribute declarations are always contained within a complex type definition.
      Properly built schemas must declare attributes at the very end of a complex type definition, after all other components of the complex type have been specified.
      <xsd:attribute name=”contentType” use=”required”>
      <xsd:restriction base=”xsd:string”>
      <xsd:enumeration value=”Fiction”/>
      <xsd:enumeration value=”Nonfiction”/>
      <xsd:attribute name=”format” use=”required”>
      <xsd:restriction base=”xsd:string”>
      <xsd:enumeration value=”Hardback”/>
      <xsd:enumeration value=”Paperback”/>
      Any XML Schema datatype can be further restricted to a certain set of valid
      content values.
    • 10.6 Step 5: Using Datatype Declarations to Define What’s What
      As you build your custom schema :
      You need to think carefully about the type of data each element and attribute will hold, and take advantage of datatype declarations to pass the specifics to document builders and processing applications.
      After you’ve created your initial set of elements and attributes, go back and add datatype declarations to them.
      To create a simple type element whose data type is string, follow these steps:
      Create an element declaration.
      Include an xsd: prefix to specify that this is an XML Schema string datatype.
      You define datatypes for attributes in the same way.
      <element name=”title” type=”xsd:string”/>
      <attribute name=”bookbinding” type=”xsd:string”/>
    • 10.6 Step 5: Using Datatype Declarations to Define What’s What
      XML Schema supports the use of regular expressions when you define a pattern.
      <xsd:element name=”price”>
      <xsd:restriction base=”xsd:string”>
      <xsd:pattern value=”$[0-9]{1,4}.[0-9]{2}”/>
      <xsd:element name=”isbn”>
      <xsd:restriction base=”xsd:string”>
      <xsd:pattern value=”[0-1][0-9]{9}”/>
    • 10.7 Tricks of the Trade
      Here are some reminders and additional tips for building and using them:
      Use annotation and documentation
      The schema element comes first
      Tools do XML Schemas too
      Review your validation options
    • 10.8 Creating a Simple Schema
      When you’ve created all the pieces of your schema, it’s time to piece them all together to complete your little (or possibly huge) project.
      Create an XML prolog and a schema element.
      Add an xmlns attribute to the schema element to specify that the document uses the XML Schema namespace and the xsd: prefix.
      Add the element and attribute declarations.
      Save your schema document with an .xsd file extension. Example books2.xsd
      <?xml version=”1.0” encoding=”UTF-8”?>
      <?xml version=”1.0” encoding=”UTF-8”?>
      <xsd:element name=”books”>
      <xsd:element name=”book” type=”bookType”/>

    • 10.9 Using a Schema with an XML File in Word 2003
      The professional version of Word 2003 allows you to add your own schema documents to Word’s Schema library and attach these schemas to XML documents in Word.
      You can start with a new XML file, add elements from your schema, add content, and then validate the content against your schema
      Open Word 2003; then choose File➪New➪XML document.
      Click Templates and Add-Ins in the XML Structure pane to open the Templates and Add-Ins dialog box; then click the XML Schema tab.
      In the XML Schema tab, click the Add Schema button; then use the Browse window to locate the schema document you want to add (in this case, books2.xsd).
      After selecting the schema document you want, click the Open button in the Browse pane.
      Enter http://www.XMLFD.com/books2.xsd for the URI and books for the alias.
      Add new elements to your blank document by clicking the element name in the XML Structure pane
      After you’ve added all the elements in order, add content — in other words, the data, such as book title and author name — to each element.
      To deal with a validation problem, move the cursor over any such icon to view the specific error message.
      Save your XML file.
    • 10.9 Using a Schema with an XML File in Word 2003
    • 10.10 Summary
      Getting to know your data
      Defining elements
      Using content models
      Defining attributes
      Using datatypes
      Incorporating best practices
      Creating a simple XML Schema document