A DTD for Products

I l @ ve RuBoard

First, you'll look at reading data from XML files using Xerces. Reading in the product list for the BFG site serves as a good example. To see how this works, you'll begin by writing a DTD to represent products in your shopping cart application so that you can add new books to the database from an XML file (see Listing 14.1).

Listing 14.1 Product.dtd
 <?xml version='1.0' encoding='UTF-8' ?> <!ELEMENT File (Product)*> <!ELEMENT Product (Title, Authors, Price, Pubdate, Description, Categories)> <!ATTLIST Product  ISBN    CDATA     #REQUIRED > <!ELEMENT Title (#PCDATA)> <!ELEMENT Authors (Author)+> <!ELEMENT Author (#PCDATA)> <!ELEMENT Price (#PCDATA)> <!ELEMENT Pubdate (#PCDATA)> <!ELEMENT Description (#PCDATA)> <!ELEMENT Categories (Category)+> <!ELEMENT Category (#PCDATA)> 

This DTD defines a fairly straightforward XML document format ”a series of products with a number of attributes, including multiple authors and categories.

Using this DTD, you can construct a set of test product data, shown in Listing 14.2.

Listing 14.2 Products.xml
 <?xml version = "1.0" encoding = "UTF-8"?> <!DOCTYPE File SYSTEM "Product.dtd"> <File>  <Product ISBN="0672322366">   <Title>    Sams Teach Yourself Visual Basic.NET Web Programming in 21 Days   </Title>   <Authors>    <Author>Peter Aiken</Author>    <Author>Phil Syme</Author>   </Authors>   <Price>39.99</Price>   <Pubdate>12/18/2001</Pubdate>   <Description> Learn how to how to use Visual Basic.NET for Internet programming with the hands-on techniques and clear explanations used throughout this practical book. Visual Basic.NET will integrate state-of-the-art programming language features, including inheritance, polymorphism, and garbage collection. The book will explain these key concepts in a simple and practical way. Web Forms and Web Controls usher in an elegant way to make dynamic Web pages. The book will cover these topics with how-to code examples and projects. One of the newest developments in Internet programming is the use of XML and the SOAP communication protocol. .NET Web Services harness these two technologies and will be covered in later sections of the book.   </Description>   <Categories>    <Category>.NET</Category>    <Category>VB</Category>   </Categories>  </Product>  <Product ISBN="0672322854">   <Title>Real-time Interactive 3D Games</Title>   <Authors>    <Author>Allen Partridge</Author>   </Authors>   <Price>59.99</Price>   <Pubdate>11/26/2001</Pubdate>   <Description> Delve deeply into 3D character and environment design for interactive games. Real-Time Interactive 3D Games: Creating 3D Game in Macromedia Director 8.5/Shockwave Studio will teach developers how to create attention-grabbing real-time 3D games with Director 8.5/Shockwave Studio. The book is broken up into three parts: The first part demonstrates good character and environment design for interactive games. The second part presents a substantial set of tutorials on the use of 3D lingo to program games. The final part teaches developers how to build strategy and surprise into their games to give the player the best experience possible. This structure mirrors the best game development practices and gives readers the skills to go out and develop games on their own. Along the way, Partridge shares some of his own experiences in game development   </Description>   <Categories>    <Category>Games</Category>    <Category>Shockwave</Category>   </Categories>  </Product> </File> 
I l @ ve RuBoard


MySQL and JSP Web Applications. Data-Driven Programming Using Tomcat and MySQL
MySQL and JSP Web Applications: Data-Driven Programming Using Tomcat and MySQL
ISBN: 0672323095
EAN: 2147483647
Year: 2002
Pages: 203
Authors: James Turner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net