SlideShare uma empresa Scribd logo
1 de 16
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? Example ,[object Object]
 Identifying the underlying structure of an XML document makes building your schema a lot easier.,[object Object]
10.4 Step 3: Building Content Models (Cont) First, create a complex type definition for the books element. <xsd:element name=”books”>      <xsd:complexType>           <xs:sequencemaxOccurs=”unbounded”> 	<xsd:element name=”book” type=”bookType”/>           </xsd:sequence>      </xsd:complexType> </xsd:element> 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:complexType> <xsd:sequence> <xsd:element ref=”title”/> </xsd:sequence> </xsd:complexType> <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:simpleType>             <xsd:restriction base=”xsd:string”> 	<xsd:enumeration value=”Fiction”/> 	<xsd:enumeration value=”Nonfiction”/>             </xsd:restriction>       </xsd:simpleType> </xsd:attribute> <xsd:attribute name=”format” use=”required”>       <xsd:simpleType>             <xsd:restriction base=”xsd:string”> 	<xsd:enumeration value=”Hardback”/> 	<xsd:enumeration value=”Paperback”/>             </xsd:restriction>       </xsd:simpleType> </xsd:attribute> 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:simpleType>             <xsd:restriction base=”xsd:string”> 	<xsd:pattern value=”[0-9]{1,4}.[0-9]{2}”/>             </xsd:restriction>       </xsd:simpleType> </xsd:element> [0-9]{1,4}.[0-9]{2} <xsd:element name=”isbn”> <xsd:simpleType> <xsd:restriction base=”xsd:string”> <xsd:pattern value=”[0-1][0-9]{9}”/> </xsd:restriction> </xsd:simpleType> </xsd:element>
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”?> <xsd:schemaxmlns:xsd=”http://www.w3.org/2001/XMLSchema”> <?xml version=”1.0” encoding=”UTF-8”?> <xsd:schemaxmlns:xsd=”http://www.w3.org/2001/XMLSchema”> <xsd:element name=”books”> <xsd:complexType> <xsd:sequencemaxOccurs=”unbounded”> <xsd:element name=”book” type=”bookType”/> </xsd:sequence> </xsd:complexType> </xsd:element> …
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

Mais conteúdo relacionado

Mais procurados

Global Versus Local
Global Versus LocalGlobal Versus Local
Global Versus Local
LiquidHub
 
Xml Presentation-1
Xml Presentation-1Xml Presentation-1
Xml Presentation-1
Sudharsan S
 
Lesson2
Lesson2Lesson2
Lesson2
hstryk
 

Mais procurados (19)

Web Development 4 (HTML & CSS)
Web Development 4 (HTML & CSS)Web Development 4 (HTML & CSS)
Web Development 4 (HTML & CSS)
 
Global Versus Local
Global Versus LocalGlobal Versus Local
Global Versus Local
 
Web Development 3 (HTML & CSS)
Web Development 3  (HTML & CSS)Web Development 3  (HTML & CSS)
Web Development 3 (HTML & CSS)
 
Computer fundamentals-internet p2
Computer fundamentals-internet p2Computer fundamentals-internet p2
Computer fundamentals-internet p2
 
Week 2-intro-html
Week 2-intro-htmlWeek 2-intro-html
Week 2-intro-html
 
Xml
XmlXml
Xml
 
shs-adcppt1
shs-adcppt1shs-adcppt1
shs-adcppt1
 
SHS-ADC(Hyperlinks)
SHS-ADC(Hyperlinks)SHS-ADC(Hyperlinks)
SHS-ADC(Hyperlinks)
 
35 schemas
35 schemas35 schemas
35 schemas
 
Xml Presentation-1
Xml Presentation-1Xml Presentation-1
Xml Presentation-1
 
Empowerment Technologies Lecture 10 (Philippines SHS)
Empowerment Technologies Lecture 10 (Philippines SHS)Empowerment Technologies Lecture 10 (Philippines SHS)
Empowerment Technologies Lecture 10 (Philippines SHS)
 
CSS Foundations, pt 1
CSS Foundations, pt 1CSS Foundations, pt 1
CSS Foundations, pt 1
 
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web TechnologyInternet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
 
Xsd tutorial
Xsd tutorialXsd tutorial
Xsd tutorial
 
Web Page Designing
Web Page DesigningWeb Page Designing
Web Page Designing
 
Web designing using html
Web designing using htmlWeb designing using html
Web designing using html
 
Css
CssCss
Css
 
Lesson2
Lesson2Lesson2
Lesson2
 
Web Development 1 (HTML & CSS)
Web Development 1 (HTML & CSS)Web Development 1 (HTML & CSS)
Web Development 1 (HTML & CSS)
 

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

Best Practice In Nutshell
Best Practice In NutshellBest Practice In Nutshell
Best Practice In Nutshell
LiquidHub
 

Semelhante a Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blogspot.com (20)

XML Schema
XML SchemaXML Schema
XML Schema
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
Best Practice In Nutshell
Best Practice In NutshellBest Practice In Nutshell
Best Practice In Nutshell
 
Xml part4
Xml part4Xml part4
Xml part4
 
O9schema
O9schemaO9schema
O9schema
 
Schema
SchemaSchema
Schema
 
Xml11
Xml11Xml11
Xml11
 
Xml
XmlXml
Xml
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
 
SCDJWS 1. xml schema
SCDJWS 1. xml schemaSCDJWS 1. xml schema
SCDJWS 1. xml schema
 
XML Fundamentals
XML FundamentalsXML Fundamentals
XML Fundamentals
 
XML.ppt
XML.pptXML.ppt
XML.ppt
 
Xsd
XsdXsd
Xsd
 
Handling tree control events
Handling tree control eventsHandling tree control events
Handling tree control events
 
XML and XSLT
XML and XSLTXML and XSLT
XML and XSLT
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
Xml
XmlXml
Xml
 
XML
XMLXML
XML
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 

Mais de phanleson

Lecture 1 - Getting to know XML
Lecture 1 - Getting to know XMLLecture 1 - Getting to know XML
Lecture 1 - Getting to know XML
phanleson
 

Mais de phanleson (20)

Learning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with SparkLearning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with Spark
 
Firewall - Network Defense in Depth Firewalls
Firewall - Network Defense in Depth FirewallsFirewall - Network Defense in Depth Firewalls
Firewall - Network Defense in Depth Firewalls
 
Mobile Security - Wireless hacking
Mobile Security - Wireless hackingMobile Security - Wireless hacking
Mobile Security - Wireless hacking
 
Authentication in wireless - Security in Wireless Protocols
Authentication in wireless - Security in Wireless ProtocolsAuthentication in wireless - Security in Wireless Protocols
Authentication in wireless - Security in Wireless Protocols
 
E-Commerce Security - Application attacks - Server Attacks
E-Commerce Security - Application attacks - Server AttacksE-Commerce Security - Application attacks - Server Attacks
E-Commerce Security - Application attacks - Server Attacks
 
Hacking web applications
Hacking web applicationsHacking web applications
Hacking web applications
 
HBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designHBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table design
 
HBase In Action - Chapter 10 - Operations
HBase In Action - Chapter 10 - OperationsHBase In Action - Chapter 10 - Operations
HBase In Action - Chapter 10 - Operations
 
Hbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBaseHbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBase
 
Learning spark ch11 - Machine Learning with MLlib
Learning spark ch11 - Machine Learning with MLlibLearning spark ch11 - Machine Learning with MLlib
Learning spark ch11 - Machine Learning with MLlib
 
Learning spark ch10 - Spark Streaming
Learning spark ch10 - Spark StreamingLearning spark ch10 - Spark Streaming
Learning spark ch10 - Spark Streaming
 
Learning spark ch09 - Spark SQL
Learning spark ch09 - Spark SQLLearning spark ch09 - Spark SQL
Learning spark ch09 - Spark SQL
 
Learning spark ch07 - Running on a Cluster
Learning spark ch07 - Running on a ClusterLearning spark ch07 - Running on a Cluster
Learning spark ch07 - Running on a Cluster
 
Learning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark ProgrammingLearning spark ch06 - Advanced Spark Programming
Learning spark ch06 - Advanced Spark Programming
 
Learning spark ch05 - Loading and Saving Your Data
Learning spark ch05 - Loading and Saving Your DataLearning spark ch05 - Loading and Saving Your Data
Learning spark ch05 - Loading and Saving Your Data
 
Learning spark ch04 - Working with Key/Value Pairs
Learning spark ch04 - Working with Key/Value PairsLearning spark ch04 - Working with Key/Value Pairs
Learning spark ch04 - Working with Key/Value Pairs
 
Learning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with SparkLearning spark ch01 - Introduction to Data Analysis with Spark
Learning spark ch01 - Introduction to Data Analysis with Spark
 
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about LibertagiaHướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
 
Lecture 1 - Getting to know XML
Lecture 1 - Getting to know XMLLecture 1 - Getting to know XML
Lecture 1 - Getting to know XML
 
Lecture 4 - Adding XTHML for the Web
Lecture  4 - Adding XTHML for the WebLecture  4 - Adding XTHML for the Web
Lecture 4 - Adding XTHML for the Web
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

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

  • 1. XML For Dummies Book Author : Lucinda Dykes & Ed Tittle Slides Prepared By: Son TN Chapter 10 :Building a Custom XML Schema
  • 2. 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
  • 3. 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.
  • 4. 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?
  • 5.
  • 6.
  • 7. 10.4 Step 3: Building Content Models (Cont) First, create a complex type definition for the books element. <xsd:element name=”books”> <xsd:complexType> <xs:sequencemaxOccurs=”unbounded”> <xsd:element name=”book” type=”bookType”/> </xsd:sequence> </xsd:complexType> </xsd:element> 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.
  • 8. 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:complexType> <xsd:sequence> <xsd:element ref=”title”/> </xsd:sequence> </xsd:complexType> <xsd:element name=”title”/> <xsd:element name=”book” type=”bookType”/>
  • 9. 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:simpleType> <xsd:restriction base=”xsd:string”> <xsd:enumeration value=”Fiction”/> <xsd:enumeration value=”Nonfiction”/> </xsd:restriction> </xsd:simpleType> </xsd:attribute> <xsd:attribute name=”format” use=”required”> <xsd:simpleType> <xsd:restriction base=”xsd:string”> <xsd:enumeration value=”Hardback”/> <xsd:enumeration value=”Paperback”/> </xsd:restriction> </xsd:simpleType> </xsd:attribute> Any XML Schema datatype can be further restricted to a certain set of valid content values.
  • 10. 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”/>
  • 11. 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:simpleType> <xsd:restriction base=”xsd:string”> <xsd:pattern value=”[0-9]{1,4}.[0-9]{2}”/> </xsd:restriction> </xsd:simpleType> </xsd:element> [0-9]{1,4}.[0-9]{2} <xsd:element name=”isbn”> <xsd:simpleType> <xsd:restriction base=”xsd:string”> <xsd:pattern value=”[0-1][0-9]{9}”/> </xsd:restriction> </xsd:simpleType> </xsd:element>
  • 12. 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
  • 13. 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”?> <xsd:schemaxmlns:xsd=”http://www.w3.org/2001/XMLSchema”> <?xml version=”1.0” encoding=”UTF-8”?> <xsd:schemaxmlns:xsd=”http://www.w3.org/2001/XMLSchema”> <xsd:element name=”books”> <xsd:complexType> <xsd:sequencemaxOccurs=”unbounded”> <xsd:element name=”book” type=”bookType”/> </xsd:sequence> </xsd:complexType> </xsd:element> …
  • 14. 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.
  • 15. 10.9 Using a Schema with an XML File in Word 2003
  • 16. 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