Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


General Structure of XML Documents - Page 3

December 2, 2002

The following listing shows the general tree structure of a content document for the simple CMS application:

Here is the DTD for the above:

<!DOCTYPE CONTENT[
  <!ELEMENT CONTENT (TITLE,AUTHORS,PAGE,BODY)>
    <!ATTLIST CONTENT TYPE CDATA #REQUIRED>
    <!ATTLIST CONTENT SUBTYPE CDATA #REQUIRED>
<!ELEMENT TITLE (#PCDATA)>
<!ELEMENT AUTHORS (FNAME,MNAME,LNAME)>
<!ELEMENT FNAME (#PCDATA)>
<!ELEMENT MNAME (#PCDATA)>
<!ELEMENT LNAME (#PCDATA)>
<!ELEMENT PAGE (#PCDATA)>
    <!ATTLIST PAGE URL CDATA #IMPLIED>
<!ELEMENT BODY (#PCDATA)>

]>

All documents imported into this simple CMS database must follow this skeleton structure; the documents will differ only in the <body> element's subtree structure. The equivalent XML template looks like this:

<content type="__type__" subtype="__subtype__">
  <title>__title__</title>
  <authors>
    <author>
      <fname>__firstname__</fname>
      <mname>__middlename__</mname>
      <lname>__lastname__</lname>
    </author>
  </authors>
  <page url="__url__"/> <!-- Attribute 'url' is optional -->
  <body>
  __body_of_content__
  </body>
</content>

Values for attributes and tags are shown as field markers, in bold. For example, the value of type is indicated by the marker __type__. When a document is added to the database, only the above tags will be parsed. Everything in the <body> element will be stored as a block of XML-like markup. The XML PI that starts every XML file will be stripped off.

The resulting <body> block will be parsed later by an application component that knows how to process the particular document type/subtype. That component is not talked about here though. Such components are not dicussed in this chapter. Example 1: Non-fiction Book (Beginning Stages) This example represents a non-fiction book. The following XML listing (nonfic01.xml) is broken up into sections in order to explain the tags:

<?xml version="1.0" ?>

Each document must start with the root element <content> and include two attributes – type and subtype (subtype can be a blank string). The resulting combination of attribute values will determine the structure of the sub-document within the <body>...</body> tag block.

<content type="nonfiction" subtype="book">

The combination of type, subtype, and the title must be unique. In other words, for a given type/subtype combination, all relevant documents must have a unique title:

<title>Web Development Methodologies</title>

Note, however, that titles can be repeated in a different type/subtype combination. Each document may have one or more contributors. For each author, use one <author>...</author> block. This block defines two authors:

<authors>
  <author>
    <fname>mary</fname>
    <mname>elizabeth</mname>
    <lname>smith</lname>
  </author>
  <author>
    <fname>john</fname>
    <mname>q</mname>
    <lname>doe</lname>
  </author>
</authors>

Specifications - Page 2
Professional PHP4 Web Development Solutions
General Structure of XML Documents - - Page 4


Up to => Home / Authoring / Languages / PHP / WebDevSolutions




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers