0% found this document useful (0 votes)
103 views35 pages

Soa

Here is the schema with target namespace and qualified elements/attributes: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/PurchaseOrder" xmlns="http://www.example.com/PurchaseOrder"> <xsd:complexType name="PurchaseOrderType"> <xsd:all> <xsd:element name="ShippingInformation" type="InfoType" minOccurs="1" maxOccurs="1"/> <xsd:element name="BillingInformation" type="InfoType" minOccurs="1" maxOccurs="1"/> <xsd:element name="Order" type="Order

Uploaded by

gomathynayagam m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views35 pages

Soa

Here is the schema with target namespace and qualified elements/attributes: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/PurchaseOrder" xmlns="http://www.example.com/PurchaseOrder"> <xsd:complexType name="PurchaseOrderType"> <xsd:all> <xsd:element name="ShippingInformation" type="InfoType" minOccurs="1" maxOccurs="1"/> <xsd:element name="BillingInformation" type="InfoType" minOccurs="1" maxOccurs="1"/> <xsd:element name="Order" type="Order

Uploaded by

gomathynayagam m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Recap

• DTD attributes
• Attributes type
• Default attribute value
• DTD Entities
• Internal entities
• External entities
• Pre-defined entities
• External Entities
• Parameter entities

Date: 11.07.2019
XML schema
• An XML schema is used to define the structure
of an XML document.
• It is like DTD but provides more control on XML
structure.
• The XML Schema language is referred to as XML
Schema Definition (XSD)
• XML Schema Definition Language at
http://www.w3c.org/XML/Schema.
Contactlist.xsd
• <?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name=“contactlist">
<xs:complexType>
<xs:sequence>
<xs:element name=“fullname" type="xs:string"/>
<xs:element name=“address" type="xs:string"/>
<xs:element name=“phone" type="xs:string"/>
<xs:element name=“email" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
PurchaseOrder.xml Contains a Sample Purchase Order
for Common Items found in a Grocery Store
<PurchaseOrder Tax=”5.76” Total=”75.77”> PurchaseOrder.xml
<ShippingInformation>
<Name>Dillon Larsen</Name>
<Address>
<Street>123 Jones Rd.</Street>
<City>Houston</City>
<State>TX</State>
<Zip>77381</Zip>
</Address>
<Method>USPS</Method>
<DeliveryDate>2001-08-12</DeliveryDate>
</ShippingInformation>
<BillingInformation>
<Name>Madi Larsen</Name>
<Address>
<Street>123 Jones Rd.</Street>
<City>Houston</City>
<State>TX</State>
<Zip>77381</Zip>
</Address>
<PaymentMethod>Credit card</PaymentMethod>
<BillingDate>2001-08-09</BillingDate>
</BillingInformation>
<Order SubTotal=”70.01” ItemsSold=”17”>
<Product Name=”Baby Swiss” Id=”702890”
Price=”2.89” Quantity=”1”/>
<Product Name=”Hard Salami” Id=”302340”
Price=”2.34” Quantity=”1”/>
</Order>
</PurchaseOrder>
• Declaring Attributes
– Attributes provide additional information to
elements.
– To indicate that a complex element has an
attribute, use the <attribute> element of the XML
Schema Definition Language.
<xsd:complexType name=”ProductType”>
<xsd:attribute name=”Name” type=”xsd:string”/>
<xsd:attribute name=”Id” type=”xsd:positiveInteger”/>
<xsd:attribute name=”Price”>
<xsd:simpleType>
<xsd:restriction base=”xsd:decimal”>
<xsd:fractionDigits value=”2”/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name=”Quantity” type=”xsd:positiveInteger”/>
</xsd:complexType>
• anyURI
primitive data type
• base64Binary
• Boolean
• date
• dateTime
• decimal
• double
• duration
• Float
• gDay
• gMonth
• gMonthDay
• gYear
• gYearMonth
• hexBinary
• NOTATION
• Qname
• string
• time
Derived data type
• Byte
• ENTITIES
• ENTITY
• ID
• IDREF
• IDREFS
• int
• integer
• language
• long
• Name
• Declaring Elements
– Elements within an XML schema can be declared using the
<element> element from the XML Schema Definition
Language.
• Syntax
<element name=”” [type=””] [abstract=””] [block=””]
[default=””] [final=””] [fixed=””] [minOccurs=””]
[maxOccurs=””] [nillable=””] [ref=””] [substitutionGroup=””]/
– The abstract attribute indicates whether the element
being declared may show up directly within the XML
document
– this element must be referenced by another element using
the substitutionGroup attribute.
<xsd:element name=’PurchaseOrder’
type=’PurchaseOrderType’/>
<xsd:complexType name=”PurchaseOrderType”>
<xsd:all> the child elements can appear in any order

<xsd:element name=”ShippingInformation”
type=”InfoType” minOccurs=”1” maxOccurs=”1”/>
<xsd:element name=”BillingInformation”
type=”InfoType” minOccurs=”1” maxOccurs=”1”/>
<xsd:element name=”Order” type=”OrderType”
minOccurs=”1” maxOccurs=”1”/>
</xsd:all>
• Declaring Complex Elements
– <complexType> element is used to define an element that contain
child elements and/or attributes.

<xsd:complexType name=’’ [abstract=’’] [base=’’] [block=’’] [final=’’]


[mixed=’’]/>

• The abstract attribute indicates whether an element may define its content
directly from this type definition
– If this attribute is true, an element must define its content from a
derived type definition.
– If this attribute is omitted or its value is false, an element may define its
content directly based on this type definition.
• The base attribute specifies the data type for the element.
• The block attribute indicates what types of derivation are prevented for this
element definition. This attribute can contain any of the following values:
– all
– extension
– restriction
Ex:Complex Elements
<xsd:element name=’PurchaseOrder’
type=’PurchaseOrderType’/>
<xsd:complexType name=”PurchaseOrderType”>
<xsd:all>
<xsd:element name=”ShippingInformation”
type=”InfoType” minOccurs=”1” maxOccurs=”1”/>
<xsd:element name=”BillingInformation”
type=”InfoType” minOccurs=”1” maxOccurs=”1”/>
<xsd:element name=”Order” type=”OrderType”
minOccurs=”1” maxOccurs=”1”/>
</xsd:all>
• Declaring Simple Types
– It is used to define single element in an XML
scheme
– Syntax
<xsd:simpleType name=’’>
<xsd:restriction base=’’/>
</xsd:simpleType>
<xsd:attribute name=”Price”>
<xsd:simpleType>
<xsd:restriction base=”xsd:decimal”>
<xsd:fractionDigits value=”2”/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
• Refining Simple Types Using Facets
– Facets give greater control over the definition of elements
and attributes.
– A facet can only be specified for a <simpleType> element,
and it helps determine the set of values for a <simpleType>
element.
• enumeration
• fractionDigits
• length
• maxExclusive
• maxInclusive
• maxLength
• minExclusive
• minInclusive
• minLength
• pattern
< xsd:enumeration > facet

<xsd:simpleType name=”PaymentMethodType”>
<xsd:restriction base=”xsd:string”>
<xsd:enumeration value=”Check”/>
<xsd:enumeration value=”Cash”/>
<xsd:enumeration value=”Credit Card”/>
<xsd:enumeration value=”Debit Card”/>
<xsd:enumeration value=”Other”/>
</xsd:restriction>
</xsd:simpleType>
The <fractionDigits> facet specifies the maximum number of
decimal digits in the fractional part.

<xsd:attribute name=”SubTotal”>
<xsd:simpleType>
<xsd:restriction base=”xsd:decimal”>
<xsd:fractionDigits value=”2”/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
The <length> facet determines the number of
units of length for the specified data type
<xsd:simpleType name=”StateType”>
<xsd:restriction base=”xsd:string”>
<xsd:length value=”2”/>
<xsd:enumeration value=”AR”/>
<xsd:enumeration value=”LA”/>
<xsd:enumeration value=”MS”/>
<xsd:enumeration value=”OK”/>
<xsd:enumeration value=”TX”/>
</xsd:restriction>
</xsd:simpleType>
• The <maxLength> and <minLength> facets specify
the maximum and minimum lengths for values in the
type definition.
• The <pattern> facet applies a specific pattern that
the type definition’s value must match.

<xsd:simpleType name=”ZipType”>
<xsd:restriction base=”xsd:string”>
<xsd:minLength value=”5”/>
<xsd:maxLength value=”10”/>
<xsd:pattern value=”[0-9]{5}(-[0-9]{4})?”/>
</xsd:restriction>
</xsd:simpleType>
• Anonymous Type Declarations
– Sometimes within an XML schema it may not be
necessary to create a separate type definition for
an element or attribute. In such cases, you may
use “anonymous” type declarations.

<xsd:complexType name=”InfoType”>
<xsd:sequence>
<xsd:element name=”Name” minOccurs=”1” maxOccurs=”1”>
<xsd:simpleType>
<xsd:restriction base=”xsd:string”/>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”Address” type=”AddressType”
minOccurs=”1” maxOccurs=”1”/>
• Targeting namespace
• Inheriting from others
Class poll
1. Schema is an _____ based alternative

XHTML

XML

XSL

XSLT
Answer

1. Schema is an _____ based alternative


XHTML
XML
XSL
XSLT
2. XSD is:

XHTML Schema Definition

XSL Schema Definition

XML Schema Definition

XSLT Schema Definition


Answer

2. XSD is:

XHTML Schema Definition

XSL Schema Definition

XML Schema Definition

XSLT Schema Definition


3.XML Schemas are the Successors of

DTD

XML

XSL

XSLT
Answer
3.XML Schemas are the Successors of

DTD

XML

XSL

XSLT
4.One of the greatest strength of XML Schemas is the support
for

images

data types

graphics

functions
Answer
4.One of the greatest strength of XML Schemas is the support
for

images

data types

graphics

functions
05. The syntax for defining an attribute is:

<xs:attribute name="xxx" type="yyy"/>

<xs:attribute name="xxx" />

<attribute name="xxx" type="yyy"/>

<xs:attribute name=xxx type=yyy/>


Answer
05. The syntax for defining an attribute is:

<xs:attribute name="xxx" type="yyy"/>

<xs:attribute name="xxx" />

<attribute name="xxx" type="yyy"/>

<xs:attribute name=xxx type=yyy/>


Exercise
Create a PurchaseOrder2.xsd that Contains the
Schema Definition for PurchaseOrder.xml with
a Target Namespace and Qualified Elements
and Attributes
<xsd:complexType name=”PurchaseOrderType”>
<xsd:all>
<xsd:element name=”ShippingInformation” type=”InfoType” minOccurs=”1”
maxOccurs=”1”/>
<xsd:element name=”BillingInformation” type=”InfoType” minOccurs=”1”
maxOccurs=”1”/>
<xsd:element name=”Order” type=”OrderType” minOccurs=”1” maxOccurs=”1”/>
</xsd:all>
<xsd:attribute name=”Tax”>
<xsd:simpleType>
<xsd:restriction base=”xsd:decimal”>
<xsd:fractionDigits value=”2”/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name=”Total”>
<xsd:simpleType>
<xsd:restriction base=”xsd:decimal”>
<xsd:fractionDigits value=”2”/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>

You might also like