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


Either/Or

May 3, 1999

The pipe character is used to specify an "OR" operation. Thus, the following DTD snippet would specify an XML document in which all CONTACT elements would have a NAME child followed by either a PHONE or an EMAIL element (but not both).

	<!ELEMENT CONTACT (NAME, (PHONE | EMAIL))>
	<!ELEMENT NAME (#PCDATA)>
	<!ELEMENT EMAIL (#PCDATA)>

Note that XML regular expression matching does not perform short circuited logic. OR's imply one or the other but not both and not neither. Is that a tongue twister or what!?! Using examples to make my point, here are several invalid XML snippets based on the DTD snippet above....

        <CONTACT>
        <NAME>Jim Sanger</NAME>
        </CONTACT>

That is invalid because the DTD specified that every CONTACT must have either a PHONE or an EMAIL. The above has neither.

        <CONTACT>
        <NAME>Jim Sanger</NAME>
        <EMAIL>Jim Sanger</EMAIL>
        <PHONE>Jim Sanger</PHONE>
        </CONTACT>

This one is invalid because the contact has BOTH EMAIL and PHONE children.

        <CONTACT>
        <EMAIL>Jim Sanger</EMAIL>
        <NAME>Jim Sanger</NAME>
        </CONTACT>

This one is wrong because NAME must appear before EMAIL or PHONE.

NOTE: within a grouping, you may use only one connector (such as , or |). Thus, it is invalid to use

	<!ELEMENT CONTACT (NAME, PHONE | EMAIL)>

Instead, you must create a subgroup.

	<!ELEMENT CONTACT (NAME, (PHONE | EMAIL))>

Grouping Elements
Introduction to XML For Web Developers | Table of Contents
Optional Children


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