Vous êtes sur la page 1sur 9

<?xml version=1.0 encoding=UTF-8?

>
<BillingInformation>
<Name> Right Plastic Products </Name>
<BillingDate> 2002-09-15 </BillingDate>
<Address>
<Street> 158 Edward st. </Street>
<City> Brisbane </City>
<State> QLD </State>
<PostalCode> 4000 </PostalCode>
</Address>
</BillingInformation>
Listing 1 Example of an XML document instance.

<?xml version=1.0 encoding=UTF-8?>


<BillingInformation customer-type=manufacturer>
<Name> Right Plastic Products </Name>
<BillingDate> 2002-09-15 </BillingDate>
<Address>
<Street> 158 Edward st. </Street>
<City> Brisbane </City>
<State> QLD </State>
<PostalCode> 4000 </PostalCode>
</Address>
</BillingInformation>
Listing 2 Example of attribute use for Listing-1.

<?xml version=1.0 encoding=UTF-8?>


<Address>
<Street> 158 Edward st. </Street>
<City> Brisbane </City>
<State> QLD </State>
<PostalCode> 4000 </PostalCode>
</Address>
Listing 3 XML example with no associated namespace.

<?xml version=1.0 encoding=UTF-8?>


<BillingInformation customer-type=manufacturer
xmlns="http://www.plastics_supply.com/BillInfo">
<Name> Right Plastic Products </Name>
<Address xmlns="http://www.plastics_supply.com/Addr">
<Street> 158 Edward st. </Street>
<City> Brisbane </City>
<State> QLD </State>
<PostalCode> 4000 </PostalCode>
</Address>
<BillingDate> 2002-09-15 </BillingDate>
</BillingInformation>
Listing 4 An XML example using namespaces

<?xml version="1.0" encoding="UTF-8"?>


<bi:BillingInformation customer-type="manufacturer"
xmlns:bi="http://www.plastics_supply.com/BillInfo"
xmlns:addr="http://www.plastics_supply.com/Addr">
<bi:Name> Right Plastic Products </bi:Name>
<addr:Address>
<addr:Street> 158 Edward st. </addr:Street>
<addr:City> Brisbane </addr:City>
<addr:State> QLD </addr:State>
<addr:PostalCode> 4000 </addr:PostalCode>
</addr:Address>
<bi:BillingDate> 2002-09-15 </bi:BillingDate>
</bi:BillingInformation>
Listing 5 Using qualified names in XML.

<?xml version="1.0" encoding="UTF-8"?>


<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:PO="http://www.plastics_supply.com/PurchaseOrder"
targetNamespace="http://www.plastics_supply.com/PurchaseOrder">
<!-- Purchase Order schema -->
<xsd:element name="PurchaseOrder" type="PO:PurchaseOrderType"/>
<xsd:complexType name="PurchaseOrderType">
<xsd:all>
<xsd:element name="ShippingInformation" type="PO:Customer"
minOccurs="1" maxOccurs="1"/>
<xsd:element name="BillingInformation" type="PO:Customer"
minOccurs="1" maxOccurs="1"/>
<xsd:element name="Order" type="PO:OrderType" minOccurs="1"
maxOccurs="1"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="Customer">
<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="PO:AddressType"
maxOccurs="1"/>
<xsd:choice>
<xsd:element name="BillingDate" type=" xsd:date "/>
<xsd:element name="ShippingDate" type=" xsd:date "/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="AddressType">
<xsd:sequence>
<xsd:element name="Street"
<xsd:element name="City"
<xsd:element name="State"
<xsd:element name="PostalCode "
<xsd:sequence>
</xsd:complexType>

type="xsd:string"/>
type="xsd:string"/>
type="xsd:string"/>
type="xsd:decimal/>

<xsd:complexType name="OrderType">
<xsd:sequence>
<xsd:element name="Product" type="PO:ProductType"

minOccurs=

"1"

minOccurs= "1" maxOccurs="unbounded"/>


</xsd:sequence>
<xsd:attribute name="Total">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="ItemsSold" type="xsd:positiveInteger"/>
</xsd:complexType>
<xsd:complexType name="ProductType">
<xsd:attribute name="Name" type="xsd:string"/>
<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>
</xsd:schema>
Listing 6 A sample purchase order schema.

<?xml version="1.0" encoding="UTF-8"?>


<PO:PurchaseOrder
xmlns:PO="http://www.plastics_supply.com/PurchaseOrder"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.plastics_supply.com/PurchaseOrder
purchaseOrder.xsd">
<ShippingInformation>
<Name> Right Plastic Products Co. </Name>
<Address>
<Street> 459 Wickham st. </Street>
<City> Fortitude Valley </City>
<State> QLD </State>
<PostalCode> 4006 </PostalCode>
</Address>
<ShippingDate> 2002-09-22 </ShippingDate>
</ShippingInformation>
<BillingInformation>
<Name> Right Plastic Products Inc. </Name>
<Address>
<Street> 158 Edward st. </Street>
<City> Brisbane </City>
<State> QLD </State>
<PostalCode> 4000 </PostalCode>
</Address>
<BillingDate> 2002-09-15 </BillingDate>
</BillingInformation>
<Order Total="253000.00" ItemsSold="2">
<Product Name="Injection Molder" Price="250000.00"
Quantity="1"/>
<Product Name="Adjustable Worktable" Price="3000.00"
Quantity="1"/>
</Order>
</PO:PurchaseOrder>
Listing 7 An XML instance document conforming to the schema in Listing-6.

<?xml version="1.0" encoding="UTF-8"?>


<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:PO="http://www.plastics_supply.com/PurchaseOrder"
targetNamespace="http://www.plastics_supply.com/PurchaseOrder">
<xsd:complexType name="Address">
<xsd:sequence>
<xsd:element name="Number" type="xsd:decimal"/>
<xsd:element name="Street" type="xsd:string"/>
<xsd:element name="City" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="AustralianAddress">
<xsd:complexContent>
<xsd:extension base="PO:Address">
<xsd:sequence>
<xsd:element
type="xsd:string"/>
<xsd:element
type="xsd:decimal"/>
<xsd:element
type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>

name="State"
name="PostalCode"
name="Country"

Listing 8 Extending XML complex types.

<!-- Uses the data type declarations from Listing 8 -->


<xsd:complexType name="AustralianPostalAddress">
<xsd:complexContent>
<xsd:restriction base="PO:AustralianAddress">
<xsd:sequence>
<xsd:element name="Number" type="xsd:decimal"/>
<xsd:element name="Street" type="xsd:string"/>
<xsd:element name="City" type="xsd:string" minOccurs="0"
maxOccurs="0"/>
<xsd:element name="State" type="xsd:string"/>
<xsd:element name="PostalCode" type="xsd:decimal"/>
<xsd:element name="Country" type="xsd:string"/>
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
Listing 9 Defining complex types by restriction.

<!-- Uses the data type declarations from Listing 8 -->


<xsd:complexType name="PurchaseOrder">
<xsd:sequence>
<xsd:element name="Name" minOccurs="1" maxOccurs="1">
<xsd:simpleType>
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:element>
<xsd:element name="shippingAddress" type="PO:Address" minOccurs= "1"
maxOccurs="1"/>
<xsd:element name="billingAddress" type="PO:Address" minOccurs= "1"
maxOccurs="1"/>
<xsd:choice minOccurs="1" maxOccurs="1">
<xsd:element name="BillingDate" type="xsd:date"/>
<xsd:element name="ShippingDate" type="xsd:date"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
Listing 10 Defining types polymorphically.

<!-- Uses type declarations from Listing 10 -->


<?xml version="1.0" encoding=UTF-8?>
<PO:PurchaseOrder xmlns:PO="http://www.plastics_supply.com/PurchaseOrder">
<Name> Plastic Products </Name>
<shippingAddress xsi:type="PO:AustralianAddress">
<Number> 459 </Number>
<Street> Wickham st. </Street>
<City> Fortitude Valley </City>
<State> QLD </State>
<PostalCode> 4006 </PostalCode>
<Country> Australia </country>
</shippingAddress>
<billingAddress xsi:type=="PO:AustralianAddress">
<Number> 158 </Number>
<Street> Edward st. </Street>
<State> QLD </State>
<PostalCode> 4000 </PostalCode>
<Country> Australia </Country>
</billingAddress>
<BillingDate> 2002-09-15 </BillingDate>
</PO:PurchaseOrder>
Listing 11 Using polymorphism in an XML schema instance.

<?xml version="1.0" encoding="UTF-8"?>


<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:PO="http://www.plastics_supply.com/PurchaseOrder"
targetNamespace="http://www.plastics_supply.com/PurchaseOrder">
<xsd:complexType name="Customer">
<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="PO:AddressType"
minOccurs= "1" maxOccurs="1"/>
<xsd:choice minOccurs="1" maxOccurs="1">
<xsd:element name="BillingDate" type="xsd:date"/>
<xsd:element name="ShippingDate" type="xsd:date"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Listing 12 Sample customer sub-schema.

<?xml version="1.0" encoding=UTF-8?>


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:PO="http://www.plastics_supply.com/PurchaseOrder"
targetNamespace="http://www.plastics_supply.com/PurchaseOrder">
<xsd:include
schemaLocation="http://www.plastics_supply.com/customerType.xsd"/>
<xsd:include
schemaLocation="http://www.plastics_supply.com/productType.xsd"/>
<xsd:element name="PurchaseOrder" type="PO:PurchaseOrderType"/>
<xsd:complexType name="PurchaseOrderType">
<xsd:all>
<xsd:element name="ShippingInformation" type="PO:Customer"
minOccurs="1" maxOccurs="1"/>
<xsd:element name="BillingInformation" type="PO:Customer"
minOccurs="1" maxOccurs="1"/>
<xsd:element name="Order" type="PO:OrderType" minOccurs= "1"
maxOccurs="1"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="AddressType">
<xsd:sequence>
<xsd:element name="Street"
<xsd:element name="City"
<xsd:element name="State"
<xsd:element name="PostalCode "
<xsd:sequence>
</xsd:complexType>

type="xsd:string"/>
type="xsd:string"/>
type="xsd:string"/>
type="xsd:decimal/>

<xsd:complexType name="OrderType">
<xsd:sequence>
<xsd:element name="Product" type="PO:ProductType"
minOccurs= "1" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="Total">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">

<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="ItemsSold" type="xsd:positiveInteger"/>
</xsd:complexType>
</xsd:schema>
Listing 13 Using the include element in the purchase order schema.

<?xml version="1.0" encoding=UTF-8?>


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:addr=http://www.plastics_supply.com/NewAddress
targetNamespace="http://www.plastics_supply.com/NewAddress">
<xsd:import namespace="http://www.plastics_supply.com/Address"
schemaLocation="addressType.xsd"/>
<xsd:complexType name="AddressType" abstract="true">
<xsd:sequence>
<xsd:element name="Number"
type="xsd:decimal"/>
<xsd:element name="Street"
type="xsd:string"/>
<xsd:element name="City"
type="xsd:string" minOccurs="0"/>
<xsd:sequence>
</xsd:complexType>
<xsd:complexType name="AustralianAddress">
<xsd:complexContent>
<xsd:extension base="addr:AddressType">
<xsd:sequence>
<xsd:element name="State"
type="xsd:string"/>
<xsd:element name="PostalCode "
type="xsd:decimal/>
<xsd:element name="Country"
type="xsd:string"/>
<xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complextype>
<xsd:complexType name="AustralianPostalAddress">
< xsd:complexContent>
<xsd:restriction base="addr:AusttralianAddress">
<xsd:sequence>
<xsd:element name="Number"
type="xsd:decimal"/>
<xsd:element name="Street"
type="xsd:string"/>
<xsd:element name="State"
type="xsd:string"/>
<xsd:element name="PostalCode "
type="xsd:decimal>
<xsd:element name="Country"
type="xsd:string"/>
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complextype>
</xsd:schema>
Listing 14 The address markup schema.

<?xml version="1.0" encoding=UTF-8?>


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
targetNamespace=http://www.plastics_supply.com/PurchaseOrder
xmlns:PO="http://www.plastics_supply.com/PurchaseOrder"
xmlns:addr="http://www.plastics_supply.com/Address">
<xsd:include
schemaLocation="http://www.plastics_supply.com/productType.xsd"/>
<xsd:import namespace="http://www.plastics_supply.com/Address"
schemaLocation="http://www.plastics_supply.com/addressType.xsd"/>
<xsd:element name="PurchaseOrder" type="PO:PurchaseOrderType"/>
<xsd:complexType name="PurchaseOrderType">
<xsd:all>
<xsd:element name="ShippingInformation" type="PO:Customer"
minOccurs="1" maxOccurs="1"/>
<xsd:element name="BillingInformation" type="PO:Customer"
minOccurs="1" maxOccurs="1"/>
<xsd:element name="Order" type="OrderType" minOccurs= "1"
maxOccurs="1"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="Customer">
<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="addr:AddressType"
minOccurs= "1" maxOccurs="1"/>
<xsd:choice minOccurs="1" maxOccurs="1">
<xsd:element name="BillingDate" type="xsd:date"/>
<xsd:element name="ShippingDate" type="xsd:date"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="OrderType">
<xsd:sequence>
<xsd:element name="Product" type="PO:ProductType"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="Total">
<xsd:simpleType>
<xsd:restriction base="xsd:decimal">
<xsd:fractionDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="ItemsSold" type="xsd:positiveInteger"/>
</xsd:complexType>
</xsd:schema>
Listing 15 A purchase order schema using import and include statements together.

XPath Query#1: /PurchaseOrder/Order[2]/child::*


Resulting Node Set#1:
=====================
<Product Name="Adjustable Worktable" Price="3000.00"
Quantity="1"/>
Listing 16 Sample XPath query and resulting node set.

Vous aimerez peut-être aussi