XML For Dummies<br />Book Author : Lucinda Dykes & Ed Tittle<br />Slides Prepared By: Son TN<br />Chapter 10 :Building a C...
Contents<br />Doing the Validity Rag<br />Step 1: Understanding Your Data<br />Step 2: Being the Root of All Structure: El...
10.1 Doing the Validity Rag<br />An XML document is valid if it conforms to the rules you define in your schema.<br />Vali...
10.2 Step 1: Understanding Your Data<br />Before building a custom schema :<br />Understand the basic nature and function ...
10.3 Step 2: Being the Root of All Structure: Elements<br />Elements define the basic structure for any XML document, incl...
 Identifying the underlying structure of an XML document makes building your schema a lot easier.</li></li></ul><li>10.4 S...
10.4 Step 3: Building Content Models (Cont)<br />First, create a complex type definition for the books element.<br />&lt;x...
10.4  Step 3: Building Content Models (Cont)<br />When you use a sequence compositor, you specify child elements in one of...
10.5 Step 4: Using Attributes to ShedLight on Data Structure<br />Attribute declarations are always contained within a com...
10.6 Step 5: Using Datatype Declarations to Define What’s What<br />As you build your custom schema :<br />You need to thi...
10.6 Step 5: Using Datatype Declarations to Define What’s What<br />XML Schema supports the use of regular expressions whe...
10.7 Tricks of the Trade<br />Here are some reminders and additional tips for building and using them:<br />Use annotation...
10.8 Creating a Simple Schema<br />When you’ve created all the pieces of your schema, it’s time to piece them all together...
10.9 Using a Schema with an XML File in Word 2003<br />The professional version of Word 2003 allows you to add your own sc...
10.9 Using a Schema with an XML File in Word 2003<br />
10.10 Summary<br />Getting to know your data<br />Defining elements<br />Using content models<br />Defining attributes<br ...
Upcoming SlideShare
Loading in …5
×

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

4,230 views

Published on

it-slideshares.blogspot.com

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,230
On SlideShare
0
From Embeds
0
Number of Embeds
37
Actions
Shares
0
Downloads
48
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

  1. 1. XML For Dummies<br />Book Author : Lucinda Dykes & Ed Tittle<br />Slides Prepared By: Son TN<br />Chapter 10 :Building a Custom XML Schema<br />
  2. 2. Contents<br />Doing the Validity Rag<br />Step 1: Understanding Your Data<br />Step 2: Being the Root of All Structure: Elements<br />Step 3: Building Content Models<br />Step 4: Using Attributes to Shed Light on Data Structure<br />Step 5: Using Datatype Declarations to Define What’s What<br />Tricks of the Trade<br />Creating a Simple Schema<br />Using a Schema with an XML File in Word 2003<br />
  3. 3. 10.1 Doing the Validity Rag<br />An XML document is valid if it conforms to the rules you define in your schema.<br />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.<br />Building a simple XML Schema requires these steps:<br />Understand your data.<br />Create element declarations.<br />Define content models.<br />Create attribute declarations.<br />Add datatype declarations.<br />This chapter takes you through the entire process of creating a custom schema that perfectly suits your XML document’s every need.<br />
  4. 4. 10.2 Step 1: Understanding Your Data<br />Before building a custom schema :<br />Understand the basic nature and function of your data.<br />Take some time to look at the kind(s) of data you’ll be using in your XML documents<br />Example : <br />Is your data a collection of book titles, author names, and publishers?<br />Before you design your schema :<br />Need to be clear about what you want to do with the data.<br />Example :<br />Do you want to export data to a database from your XML documents, or do you want it available for access from wireless devices?<br />
  5. 5. 10.3 Step 2: Being the Root of All Structure: Elements<br />Elements define the basic structure for any XML document, including those created according to a schema.<br />After you’ve got a good handle on your data and are ready to build a schema that fits it :<br />You should first decide which elements will be included in your XML document.<br />As a first step in declaring the elements for your schema, map out the basic structure of the document:<br />What elements do you think you’ll need? <br />How do they fit together?<br />Example<br /><ul><li> A map makes deciding what kind of attributes, content models, and datatypes you need to define a lot easier.
  6. 6. Identifying the underlying structure of an XML document makes building your schema a lot easier.</li></li></ul><li>10.4 Step 3: Building Content Models<br />A content model defines the type of content that can be contained in an element.<br />The four content models for XML Schema elements is :<br />Element<br />Text<br />Mixed<br />Empty<br />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:<br />Sequence<br />Choice<br />All<br />
  7. 7. 10.4 Step 3: Building Content Models (Cont)<br />First, create a complex type definition for the books element.<br />&lt;xsd:element name=”books”&gt;<br /> &lt;xsd:complexType&gt;<br /> &lt;xs:sequencemaxOccurs=”unbounded”&gt;<br /> &lt;xsd:element name=”book” type=”bookType”/&gt;<br /> &lt;/xsd:sequence&gt;<br /> &lt;/xsd:complexType&gt;<br />&lt;/xsd:element&gt;<br />The books element in this<br />case contains all the other elements in the schema document except for<br />the schema element.<br />A sequence includes one or more element references.<br />
  8. 8. 10.4 Step 3: Building Content Models (Cont)<br />When you use a sequence compositor, you specify child elements in one of two ways:<br />By using a ref attribute with a value equal to the value of the name attribute in each child element’s element declaration.<br />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<br />&lt;xsd:complexType&gt;<br />&lt;xsd:sequence&gt;<br />&lt;xsd:element ref=”title”/&gt;<br />&lt;/xsd:sequence&gt;<br />&lt;/xsd:complexType&gt;<br />&lt;xsd:element name=”title”/&gt;<br />&lt;xsd:element name=”book” type=”bookType”/&gt;<br />
  9. 9. 10.5 Step 4: Using Attributes to ShedLight on Data Structure<br />Attribute declarations are always contained within a complex type definition.<br />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.<br />&lt;xsd:attribute name=”contentType” use=”required”&gt;<br /> &lt;xsd:simpleType&gt;<br /> &lt;xsd:restriction base=”xsd:string”&gt;<br /> &lt;xsd:enumeration value=”Fiction”/&gt;<br /> &lt;xsd:enumeration value=”Nonfiction”/&gt;<br /> &lt;/xsd:restriction&gt;<br /> &lt;/xsd:simpleType&gt;<br />&lt;/xsd:attribute&gt;<br />&lt;xsd:attribute name=”format” use=”required”&gt;<br /> &lt;xsd:simpleType&gt;<br /> &lt;xsd:restriction base=”xsd:string”&gt;<br /> &lt;xsd:enumeration value=”Hardback”/&gt;<br /> &lt;xsd:enumeration value=”Paperback”/&gt;<br /> &lt;/xsd:restriction&gt;<br /> &lt;/xsd:simpleType&gt;<br />&lt;/xsd:attribute&gt;<br />Any XML Schema datatype can be further restricted to a certain set of valid<br />content values.<br />
  10. 10. 10.6 Step 5: Using Datatype Declarations to Define What’s What<br />As you build your custom schema :<br />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.<br />After you’ve created your initial set of elements and attributes, go back and add datatype declarations to them.<br />To create a simple type element whose data type is string, follow these steps:<br /> Create an element declaration.<br />Include an xsd: prefix to specify that this is an XML Schema string datatype.<br />You define datatypes for attributes in the same way.<br />&lt;element name=”title” type=”xsd:string”/&gt;<br />&lt;attribute name=”bookbinding” type=”xsd:string”/&gt;<br />
  11. 11. 10.6 Step 5: Using Datatype Declarations to Define What’s What<br />XML Schema supports the use of regular expressions when you define a pattern.<br />&lt;xsd:element name=”price”&gt;<br /> &lt;xsd:simpleType&gt;<br /> &lt;xsd:restriction base=”xsd:string”&gt;<br /> &lt;xsd:pattern value=”$[0-9]{1,4}.[0-9]{2}”/&gt;<br /> &lt;/xsd:restriction&gt;<br /> &lt;/xsd:simpleType&gt;<br />&lt;/xsd:element&gt;<br />$[0-9]{1,4}.[0-9]{2}<br />&lt;xsd:element name=”isbn”&gt;<br />&lt;xsd:simpleType&gt;<br />&lt;xsd:restriction base=”xsd:string”&gt;<br />&lt;xsd:pattern value=”[0-1][0-9]{9}”/&gt;<br />&lt;/xsd:restriction&gt;<br />&lt;/xsd:simpleType&gt;<br />&lt;/xsd:element&gt;<br />
  12. 12. 10.7 Tricks of the Trade<br />Here are some reminders and additional tips for building and using them:<br />Use annotation and documentation<br />The schema element comes first<br />Tools do XML Schemas too<br />Review your validation options<br />
  13. 13. 10.8 Creating a Simple Schema<br />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.<br />Create an XML prolog and a schema element.<br />Add an xmlns attribute to the schema element to specify that the document uses the XML Schema namespace and the xsd: prefix.<br />Add the element and attribute declarations.<br />Save your schema document with an .xsd file extension. Example books2.xsd<br />&lt;?xml version=”1.0” encoding=”UTF-8”?&gt;<br />&lt;xsd:schemaxmlns:xsd=”http://www.w3.org/2001/XMLSchema”&gt;<br />&lt;?xml version=”1.0” encoding=”UTF-8”?&gt;<br />&lt;xsd:schemaxmlns:xsd=”http://www.w3.org/2001/XMLSchema”&gt;<br />&lt;xsd:element name=”books”&gt;<br />&lt;xsd:complexType&gt;<br />&lt;xsd:sequencemaxOccurs=”unbounded”&gt;<br />&lt;xsd:element name=”book” type=”bookType”/&gt;<br />&lt;/xsd:sequence&gt;<br />&lt;/xsd:complexType&gt;<br />&lt;/xsd:element&gt;<br />…<br />
  14. 14. 10.9 Using a Schema with an XML File in Word 2003<br />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.<br />You can start with a new XML file, add elements from your schema, add content, and then validate the content against your schema <br />Open Word 2003; then choose File➪New➪XML document.<br />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.<br />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).<br />After selecting the schema document you want, click the Open button in the Browse pane.<br />Enter http://www.XMLFD.com/books2.xsd for the URI and books for the alias.<br />Add new elements to your blank document by clicking the element name in the XML Structure pane<br />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.<br />To deal with a validation problem, move the cursor over any such icon to view the specific error message.<br />Save your XML file.<br />
  15. 15. 10.9 Using a Schema with an XML File in Word 2003<br />
  16. 16. 10.10 Summary<br />Getting to know your data<br />Defining elements<br />Using content models<br />Defining attributes<br />Using datatypes<br />Incorporating best practices<br />Creating a simple XML Schema document<br />

×