XML课本程序代码第四章例题.docx
《XML课本程序代码第四章例题.docx》由会员分享,可在线阅读,更多相关《XML课本程序代码第四章例题.docx(18页珍藏版)》请在冰豆网上搜索。
XML课本程序代码第四章例题
4_1.XML
xmlversion="1.0"encoding="UTF-8"?
>
--NewdocumentcreatedwithEditiXatThuMar2211:
37:
13CST2012-->
DOCTYPEorderSYSTEM"order.dtd">
12345678
105.99
Visa
4111*******1111
02-03-2009
JonhSmith
416-555-1234
5050MapleStreet
Toronto
Ontario
Canada
TheordersystemisforCanadiancustomersonly.
order.dtd
ELEMENTorder(order_id,amount,credit_card,date,customer,shipping_addr,comment)>
ELEMENTorder_id(#PCDATA)>
ELEMENTamount(#PCDATA)>
ELEMENTcredit_card(card_type,card_num)>
ELEMENTcard_type(#PCDATA)>
ELEMENTcard_num(#PCDATA)>
ELEMENTdate(#PCDATA)>
ELEMENTcustomer(name,phone)>
ELEMENTname(#PCDATA)>
ELEMENTphone(#PCDATA)>
ELEMENTshipping_addr(street,city,province,country)>
ELEMENTstreet(#PCDATA)>
ELEMENTcity(#PCDATA)>
ELEMENTprovince(#PCDATA)>
ELEMENTcountry(#PCDATA)>
ELEMENTcomment(#PCDATA)>
ATTLISTphonephone_type(home|work|mobile)#REQUIRED>
4_4.XML
xmlversion="1.0"encoding="UTF-8"?
>
xmlns:
xsi="http:
//www.w3.org/2001/XMLSchema-instance"
xsi:
noNamespaceSchemaLocation="country.xsd">
Canada
China
UnitedStates
country.xsd
xmlversion="1.0"encoding="UTF-8"?
>
--NewdocumentcreatedwithEditiXatThuMar2211:
44:
46CST2012-->
schemaxmlns:
xs="http:
//www.w3.org/2001/XMLSchema">
elementname="countries">
complexType>
sequence>
elementname="country"type="xs:
string"minOccurs="1"maxOccurs="unbounded"/>
sequence>
complexType>
element>
schema>
4_5.XML
xmlversion="1.0"encoding="UTF-8"?
>
xsi="htpp:
//www.w3.org/2001/XMLSchema-instance"
xsi:
noNamespaceSchemaLocation="olympic.xsd">
olympic.xsd
xmlversion="1.0"encoding="UTF-8"?
>
schemaxmlns:
xs="http:
//www.w3.org/2001/XMLSchema">
elementname="olympic">
complexType>
sequence>
elementmaxOccurs="unbounded"minOccurs="1"name="results">
complexType>
sequence>
elementmaxOccurs="unbounded"minOccurs="1"ref="country"/>
sequence>
attributeGroupref="results_attributes"/>
complexType>
element>
sequence>www.wetherm-
complexType>
element>
elementname="country">
complexType>
attributeGroupref="country_attributes"/>
complexType>
element>
attributeGroupname="results_attributes">
attributename="city"type="xs:
string"use="required"/>
attributename="year"type="xs:
integer"use="required"/>
attributeGroup>
attributeGroupname="country_attributes">
attributename="gold"type="xs:
integer"use="required"/>
attributename="rank"type="xs:
integer"use="required"/>
attributename="name"type="xs:
string"use="required"/>
attributename="code"type="xs:
string"use="required"/>
attributeGroup>
schema>
4_8.XML
xmlversion="1.0"encoding="UTF-8"?
>
countries
xmlns:
xsi="htpp:
//www.w3.org/2001/XMLSchema-instance"
xmlns:
c="http:
//javabeans.mobi/xml/demos"
xsi:
schemaLocation="http:
//javabeans.mobi/xml/demoscountry_ns.xsd">
Canada温碧泉
China
UnitedStates
countries>
country_ns.xsd
xmlversion="1.0"encoding="UTF-8"?
>
schematargetNamespace="http:
//javabeans.mobi/xml/demos"xmlns:
xs="http:
//www.w3.org/2001/XMLSchema">
elementname="countries">
complexType>
sequence>
elementmaxOccurs="unbounded"minOccurs="1"name="country"type="xs:
string"/>
sequence>
complexType>
element>
schema>
4_10
Olympic_ns_wrong.xsd
xmlversion="1.0"encoding="UTF-8"?
>
schemaxmlns:
xs="http:
//www.w3.org/2001/XMLSchema"
targetNamespace="http:
//javabeans.mobi/xml/demos">
elementname="olympic">
complexType>
sequence>
elementmaxOccurs="unbounded"minOccurs="1"name="results">
complexType>
sequence>
elementmaxOccurs="unbounded"minOccurs="1"ref="country"/>
sequence>
attributeGroupref="results_attributes"/>
--引用的是一个不具有名称空间的组件!
-->
complexType>
element>
sequence>
complexType>
element>
elementname="country">
complexType>
attributeGroupref="country_attributes"/>
--引用的是一个不具有名称空间的组件!
-->
complexType>
element>
attributeGroupname="results_attributes">
attributename="city"type="xs:
string"use="required"/>
attributename="year"type="xs:
integer"use="required"/>
attributeGroup>
attributeGroupname="country_attributes">
attributename="gold"type="xs:
integer"use="required"/>
attributename="rank"type="xs:
integer"use="required"/>
attributename="name"type="xs:
string"use="required"/>
attributename="code"type="xs:
string"use="required"/>
attributeGroup>
schema>
4_11
Olympic_ns.xsd
xmlversion="1.0"encoding="UTF-8"?
>
schemaxmlns:
xs="http:
//www.w3.org/2001/XMLSchema"
xmlns:
c="http:
//javabeans.mobi/xml/demos"
targetNamespace="http:
//javabeans.mobi/xml/demos">
elementname="olympic">
complexType>
sequence>
elementmaxOccurs="unbounded"minOccurs="1"name="results">
complexType>
sequence>
elementmaxOccurs="unbounded"minOccurs="1"ref="c:
country"/>
sequence>
attributeGroupref="c:
results_attributes"/>
complexType>
element>
sequence>
complexType>
element>
elementname="country">
complexType>
attributeGroupref="c:
country_attributes"/>
complexType>
element>
attributeGroupname="results_attributes">
attributename="city"type="xs:
string"use="required"/>
attributename="year"type="xs:
integer"use="required"/>
attributeGroup>
attributeGroupname="country_attributes">
attributename="gold"type="xs:
integer"use="required"/>
attributename="rank"type="xs:
integer"use="required"/>
attributename="name"type="xs:
string"use="required"/>
attributename="code"type="xs:
string"use="required"/>
attributeGroup>
schema>
4_12.xsd
xmlversion="1.0"encoding="UTF-8"?
>
schemaxmlns:
xs="http:
//www.w3.org/2001/XMLSchema">
elementname="olympic">
complexType>
sequence>
elementmaxOccurs="unbounded"minOccurs="1"name="results">
complexType>
sequence>
elementmaxOccurs="unbounded"minOccurs="1"ref="country"/>
sequence>
attributeGroupref="results_attributes"/>
complexType>
element>
sequence>
complexType>
element>
elementname="country">
complexType>
attributename="gold"type="xs:
integer"use="required"/>
attributename="rank"type="xs:
integer"use="required"/>
attributename="name"type="xs:
string"use="required"/>
attributename="code"type="xs:
string"use="required"/>
complexType>
element>
attributeGroupname="results_attributes">
attributename="city"type="xs:
string"use="required"/>
attributename="year"type="xs:
integer"use="required"/>
attributeGroup>
schema>
4_13.XML
xmlversion="1.0"encoding="UTF-8"?
>
xmlns:
xsi="http:
//www.w3.org/2001/XMLSchema-instance"
xsi:
noNamespaceSchemaLocation="4_13.xsd">
12345678
105.99
Visa
4111*******1111
02-03-2009
JonhSmith
416-555-1234
5050MapleStreet
Toronto
Ontario
Canada
TheordersystemisforCanadiancustomersonly.
4_13.xsd
xmlversion="1.0"encoding="UTF-8"?
>
schemaxmlns:
xs="http:
//www.w3.org/2001/XMLSchema">
elementname="order">
complexType>
sequence>
elementname="order_id"type="xs:
string"/>
elementname="amount"type="xs:
string"/>
elementref="credit_card"/>
elementname="date"type="xs:
string"/>
elementref="customer"/>
elementref="shipping_addr"/>
elementname="comment"type="xs:
string"/>
sequence>
complexType>
element>
complexTypename="credit_card_type">
sequence>
elementname="card_type"type="xs:
string"/>
elementname="card_num"type="xs:
string"/>
sequence>
complexType>
elementname="credit_card"type="credit_card_type"/>
complexTypename="customer">
sequence>
elementname="name"type="xs