 |
|
|
 |
| Web Services |
 |
| April 2003 |
 |
| DeveloperNet University Course |
 |
 |
| Reader Rating |
 |
|
 |
from ratings |
 |
|
 |
|
|
Exercise: 3 Create a DTD and Schema Document for Your XML File
In this exercise, you will see an example of a Schema and DTD document to accompany your XML file.
Report.xml
<?xml version = "1.0"?> <!DOCTYPE report SYSTEM "report.dtd"> <report> <time> <reportdate>Feb. 1, 2003</reportdate> <reporttime>8:15am</reporttime> </time> <person> <name>Tom Roberts</name> <ssn>132-456-4566</ssn> <streetaddress>87 East Park Avenue</streetaddress> <cityaddress>Springville, Utah 84987</cityaddress> </person> <account> <number>987987</number> <type>checking</type> <balance>581.23</balance> </account> <account> <number>987456</number> <type>savings</type> <balance>1510.23</balance> <accountir>1.8 %</accountir> </account> <account> <number>987457</number> <type>savings</type> <balance>6821.48</balance> <accountir>2.9%</accountir> </account> </report>
Report.dtd
<!ELEMENT report ( demo, person, account+ )>
<!ELEMENT time ( reportdate, reporttime )> <!ELEMENT reportdate ( #PCDATA )> <!ELEMENT reporttime ( #PCDATA )>
<!ELEMENT person ( name, ssn, streetaddress, cityaddress )> <!ELEMENT name ( #PCDATA )> <!ELEMENT ssn ( #PCDATA )> <!ELEMENT streetaddress ( #PCDATA )> <!ELEMENT cityaddress ( #PCDATA )>
<!ELEMENT account ( number*, type*, balance*, accountir* )> <!ELEMENT number ( #PCDATA )> <!ELEMENT balance ( #PCDATA )> <!ELEMENT type ( #PCDATA )> <!ELEMENT accountir ( #PCDATA )>
Schema.xml
<?xml version = "1.0"?>
<Schema xmlns = "urn:schemas-microsoft-com:xml-data">
<ElementType name = "reportdate" model = "closed" content = "textOnly"> </ElementType>
<ElementType name = "reporttime" model = "closed" content = "textOnly"> </ElementType>
<ElementType name = "name" model = "closed" content = "textOnly">
</ElementType>
<ElementType name = "ssn" model = "closed" content = "textOnly"> </ElementType>
<ElementType name = "streetaddress" model = "closed" content = "textOnly"> </ElementType>
<ElementType name = "cityaddress" model = "closed" content = "textOnly"> </ElementType>
<ElementType name = "number" model = "closed" content = "textOnly"> </ElementType>
<ElementType name = "type" model = "closed" content = "textOnly"> </ElementType>
<ElementType name = "balance" model = "closed" content = "textOnly"> </ElementType>
<ElementType name = "accountir" model = "closed" content = "textOnly"> </ElementType>
<ElementType name = "report" model = "open" content = "eltOnly" order = "seq"> <element type = "time" minOccurs = "1" maxOccurs = "1" /> <element type = "person" minOccurs = "1" maxOccurs = "1" /> <element type = "account" minOccurs = "1" maxOccurs = "*" /> </ElementType>
<ElementType name = "time" content = "mixed" order = "many"> <element type = "reportdate" minOccurs = "1" maxOccurs = "1" /> <element type = "reporttime" minOccurs = "1" maxOccurs = "1" /> </ElementType>
<ElementType name = "person" content = "mixed" order = "many"> <element type = "name" minOccurs = "1" maxOccurs = "1" /> <element type = "ssn" minOccurs = "1" maxOccurs = "1" /> <element type = "streetaddress" minOccurs = "1" maxOccurs = "1" /> <element type = "cityaddress" minOccurs = "1" maxOccurs = "1" /> </ElementType>
<ElementType name = "account" content = "mixed" order = "many"> <element type = "number" minOccurs = "1" maxOccurs = "1" /> <element type = "type" minOccurs = "1" maxOccurs = "1" /> <element type = "balance" minOccurs = "1" maxOccurs = "1" /> <element type = "account" minOccurs = "1" maxOccurs = "1" /> </ElementType> </Schema>
|