Электронный магазин на Java и XML

       

Финальная версия


После того как мы внесли все указанные выше исправления в первую черновую версию, мы можем скомпоновать окончательную версию определения catalog.dtd и создать пример каталога catalog.xml. Он довольно сильно отличается от первой версии и (как мы надеемся) гораздо лучше соответствует нашим требованиям. Листинг 2.6 содержит последнюю версию нашего определения DTD.

Листинг 2.6. Исправленный файл catalog .dtd

<!ENTITY % running_text "(#PCDATA | bold |

italics | quote | link | general)*">

<!ENTITY % date_time "(day_of_week?, month?,

day_of_month?, year?,(hour, minute, seconds?)?)">

<!ELEMENT catalog (product_line*) >

<!ELEMENT product_line (product*)>

<!ATTLIST product_line name CDATA #IMPLIED>

<!ELEMENT product (name,author*,artist*,description, price,quantity_in_stock,image*, onsale_date?,clip*,shipping_info*)>

<!ATTLIST product id ID #REQUIRED>

<!ATTLIST product keywords CDATA #IMPLIED>



<!ELEMENT name (#PCDATA)>

<!ELEMENT author (name)>

<!ELEMENT artist (name)>

<!ELEMENT description (paragraph|general)* >

<!ELEMENT paragraph %running_text;>

<!ELEMENT bold (#PCDATA)>

<!ELEMENT italics (#PCDATA)>

<!ELEMENT quote (#PCDATA)>

<!ATTLIST quote attrib CDATA #IMPLIED>

<!ELEMENT link (#PCDATA)>

<!ATTLIST link href CDATA #REQUIRED alt CDATA #IMPLIED>

<!ELEMENT general (#PCDATA)>

<!ATTLIST general type CDATA #REQUIRED>

<!ELEMENT price (#PCDATA)>

<!ATTLIST price discount CDATA #IMPLIED>

<!ELEMENT quantity_in_stock (#PCDATA)>

<!ELEMENT image (caption?)>

<!ATTLIST image format (gif|png|jpg) #REQUIRED width CDATA #IMPLIED height CDATA #IMPLIED src CDATA #REQUIRED>

<!ELEMENT caption (paragraph)* >

<!ELEMENT onsale_date %date_time;>

<!ELEMENT day_of_week (#PCDATA)>

<!ELEMENT month (#PCDATA)>

<!ELEMENT day_of_month (#PCDATA)>

<!ELEMENT year (#PCDATA)>


<!ELEMENT hour (#PCDATA)>

<!ELEMENT minute (#PCDATA)>

<!ELEMENT seconds (#PCDATA)>

<!ELEMENT clip (title,description?)>

<!ATTLIST clip format (mp3|mpeg|mov|rm) #REQUIRED length CDATA #IMPLIED size CDATA #IMPLIED src CDATA #REQUIRED>

<!ELEMENT title (#PCDATA)>

В листинге 2.7 содержится правильно оформленный и допустимый документ XML, в котором используется DTD из файла catalog.dtd. Это только фрагмент исходного текста для полного каталога, который вы найдете на прилагаемом к данной книге компакт-диске.



Листинг 2.7. Пример каталога из файла catalog.xml

<?xml version="1.0" standalone="no"?>

<!DOCTYPE catalog SYSTEM "catalog.dtd">

<!-- modified 10/12/2000 -->

<catalog>

<product_line name="Books">

<product id="bk0022" keywords="gardening, plants">

<name>Guide To Plants</name>

<description>

<paragraph> <italics>Everything</italics> you've ever wanted

to know about plants. </paragraph>

</description>

<price>$12.99</price>

<quantity_in_stock>4</quantity_in_stock>

<image format="gif" width="234" height="400"

src="images/covers/plantsv1.gif">

<caption>

<paragraph>This is the cover from the first

edition.</paragraph>

</caption>

</image>

<onsale_date>

<month>4</month>

<day_of_month>4</day_of_month>

<year>1999</year>

</onsale_date>

<shipping_info type="UPS" value="1.0" />

</product>

<product id="bk0023" keywords="gardening,

plants">

<name>Guide To Plants, Volume 2</name>

<description>

<paragraph>Everything else you've ever wanted

to know about plants.</paragraph>

</description>

<price>$12.99</price>

<quantity_in_stock>4</quantity_in_stock>



<image format="gif" width="234" height="400"

src="images/covers/plantsv2.gif">

<caption>

<paragraph> This is the cover from the first

edition.</paragraph>

</caption>

</image>

<onsale_date>

<month>4</month>

<day_of_month>8</day_of_month>

<year>2000</year>

</onsale_date>

<shipping_info type="UPS" value="1.0" />

</product> <product id="bk0024"

keywords="how-to, technology">

<name>The Genius's Guide to the 3rd Millenium</name>

<author>

<name>Christoph Minwich</name>

</author>

<description>

<paragraph>Learn to convert your replicator

into a transporter..and other neat tricks.</paragraph>

</description>

<price>$59.95</price>

<quantity_in_stock>0</quantity_in_stock>

<image format="gif" width="234" height="400"

src="images/covers/millenium.gif">

</image>

<onsale_date>

<month>1</month>

<day_of_month>1</day_of_month>

<year>2001</year>

</onsale_date>

<shipping_info type="UPS" value="2.0" />

</product>

<product id="bk0025" keywords="how-to, art">

<name>Dryer Lint Art</name>

<description>

<paragraph>A new book about the new folk art

that's catching on like wildfire.</paragraph>

</description>

<price>$5.95</price>

<quantity_in_stock>34</quantity_in_stock>

<image format="gif" width="200" height="200"

src="images/covers/dryerart.gif">

</image>

<onsale_date>

<month>11</month>

<day_of_month>3</day_of_month>

<year>1971</year>

</onsale_date>

<shipping_info type="UPS" value="1.5" />



</product>

</product_line>

<!-- end Book Product Line -->

<!-- being CDs Product Line -->

</product_line>

<product_line name="CDs">

<product id="cd0023" keywords="music,easy

listening,pets,dogs">

<name>Music for Dogs</name>

<description>

<paragraph> Keep your pets calm while you're

away from the house! Each of the 15 tracks

on this CD has been scientifically shown to

relax pets of all kinds.</paragraph>

</description>

<price>$14.99</price>

<quantity_in_stock>50</quantity_in_stock>

<image format="gif" width="200" height="200"

src="http://www.musicfordogs.com/images/cover.gif"> </image>

<onsale_date>

<month>3</month>

<day_of_month>2</day_of_month>

<year>1990</year>

</onsale_date>

<clip format="mp3" length="2:12" size="1.6 Mb" src="http://www.musicfordogs.com/sounds/track1.mp3">

<title>Track 1: Fetching the Stick</title>

<description>

<paragraph>An exciting and playful melody.</paragraph>

</description>

</clip>

<shipping_info type="UPS" value="0.5" />

</product>

<product id="cd0024" keywords="music,easy listening">

<name>Just Singin' Along</name>

<description>

<paragraph>A lovely collection of songs that the whole family can sing right along with.</paragraph>

</description>

<price>$10.00</price>

<quantity_in_stock>100</quantity_in_stock>

<onsale_date>

<month>2</month>

<day_of_month>23</day_of_month>

<year>2000</year>

</onsale_date>

<shipping_info type="UPS" value="0.5" />

</product>

<product id="cd0025" keywords="music,folk">



<name>It' s Dot Com Enough For Me: Songs From Silicon Somewhere</name>

<description>

<paragraph>A collection of the best folk music from Internet companies.</paragraph>

</description>

<price>$12.99</price>

<quantity_in_stock>4</quantity_in_stock>

<onsale_date>

<month>4</month>

<day_of_month>12</day_of_month>

<year>2000</year>

</onsale_date>

<clip format="mp3" length="4.32" size="4.0 Mb" src="track2.mp3">

<title>Track 2: My B2B is B-R-O-K-E</title>

</clip>

<shipping_info type="UPS" value="0.5" />

</product>

</product_line>

<!-- end CDs product line -->

<!-- begin Widgets product line -->

<product_line name="widgets">

<product id="wg0026" keywords="appliance,electronics">

<name>ElectroThermal Oxidizer</name>

<description>

<paragraph>This amazing gizmo uses electricity to produce heat that can be used for oxidization purposes.</paragraph>

</description>

<price>$24.95</price>

<quantity_in_stock>10</quantity_in_stock>

<image format="jpg" width="208" height="178" src="/images/toaster.jpg"> </image>

<onsale_date>

<month>6</month>

<day_of_month>2</day_of_month>

<year>2000</year>

</onsale_date>

<shipping_info type="UPS" value="12.0" />

</product>

<product id="wg0027" keywords="computing,

electronics, input device">

<name>Percusive Interface Unit</name>

<description>

<paragraph>Communicate with your favorite

electric calculating machine--through

tapping!</paragraph>

</description>

<price>$109.99</price>

<quantity_in_stock>7</quantity_in_stock>



<onsale_date>

<month>6</month>

<day_of_month>23</day_of_month>

<year>2001</year>

</onsale_date>

<shipping_info type="UPS" value="12.0" />

</product>

<product id="wg0028" keywords="outdoors">

<name>Umbrella</name>

<description>

<paragraph> Imagine going out into the rain and NOT getting wet! The amazing umbrella makes it possible.</paragraph>

</description>

<price>$10.99</price>

<quantity_in_stock>7</quantity_in_stock>

<onsale_date>

<month>7</month>

<day_of_month>2</day_of_month>

<year>2000</year>

</onsale_date>

<shipping_info type="UPS" value="10.0" />

</product>

<!-- end widgets product line -->

<!-- end catalog -->

</catalog>

 




Содержание раздела