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


Defining Elements and their Children

May 3, 1999

In our previous example, we explained that we had defined an element named CONTACT, that was allowed to include a single element NAME, that in turn contained parsed character data.

<?xml version = "1.0" encoding="UTF-8" standalone = "yes"?>
<!DOCTYPE CONTACTS [
   <!ELEMENT CONTACTS ANY>
   <!ELEMENT CONTACT (NAME)>
   <!ELEMENT NAME (#PCDATA)>
   ]>

<CONTACTS>

<CONTACT>
   <NAME>Roger Kaplan</NAME>
</CONTACT>

</CONTACTS>

Well, truthfully, we were "mostly" right in our explanation of the DTD. More correctly, the example defined an element named CONTACT that was REQUIRED to have a child NAME.

Remember that DTDs give you quite a bit of flexibility to specify exactly what elements can contain. Using regular expression pattern matching, DTDs allow you to specify very complex logical relationships between elements and their children.

For example, you could specify such things as: an element may contain a child, one or more children, zero or more children, or at least one child. You could also specify more complex relationships such as element X is valid if it contains one or more children named Y OR one Child named Z.

Element definitions are described by their Element Content Models (ECM), that is, all the stuff in the parentheses.

Thus, as we saw, the ECM of the CONTACT element specified the child element NAME:

<!ELEMENT CONTACT (NAME)>

The contents of the ECM are governed by a set of regular expression rules very similar to those used in UNIX. But if you are not familiar with UNIX, don't worry, it is pretty easy. The idea of regular expressions is that certain characters are used to communicate matching logic. Take a look at the possible meta characters....

Character Meaning
+ One or more occurrence
* Zero or more occurrences
? Optional
() A group of expressions to be matched together
| OR...as in, "this or that"
, Strictly ordered. Like an AND
ELEMENT_A ELEMENT_B ELEMENT_C Unordered and list.

Of course, these are best seen by example. Let's consider the simplest case of defining an order of child elements.

Element Type Declarations (ETDs)
Introduction to XML For Web Developers | Table of Contents
Ordering Child Elements


Up to => Home / Authoring / Languages / XML / Tutorials / Intro




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