Home arrow XML arrow Page 3 - XML Basics
XML

XML Basics


When I first heard about XML, I thought it was something similar to HTML. Needless to say, I was wrong. XML and HTML were designed with different goals. XML was designed to describe data and HTML was designed to display data. In this article we will try to learn some basics about XML. Then we will learn about DTD and XML schemas.

Author Info:
By: Mamun Zaman
Rating: 4 stars4 stars4 stars4 stars4 stars / 43
September 05, 2007
TABLE OF CONTENTS:
  1. · XML Basics
  2. · XML Tags and Conventions
  3. · More on Elements
  4. · XML Schema

print this article
SEARCH DEVARTICLES

XML Basics - More on Elements
(Page 3 of 4 )

Some elements may appear several times and some may not appear. In DTD, this multiplicity can also be defined.

+ defines one or more times
* defines zero or more times
? defines an optional element, that is one or not at all

Some examples of multiplicity include:

<!ELEMENT Customer (Name, CardInfo+) > : A Customer can have a mandatory Name sub-element and one or more CardInfo sub-elements.

<!ELEMENT Name (FirstName, MiddleName?, LastName) > : FirstName and LastName will appear one time and MiddleName may appear or not.

<!ELEMENT Purchase (ItemNo, Title, Price)* > : A Purchase element may have several sub-elements which include ItemNo, Title and Price or none at all.

Here is the complete DTD declaration for our book example.

<!DOCTYPE bookstore [
      <!ELEMENT bookstore (book)*>

      <!ELEMENT book (title, author, year, price)>
      <!ELEMENT title (#PCDATA)>
      <!ATTLIST title id CDATA "0">
      <!ELEMENT author (#PCDATA)>
      <!ELEMENT year (#PCDATA)>
      <!ELEMENT price (#PCDATA)>
]>

DTD can be internal or external. Internal DTD means the definition, like the one above, would be specified after the XML processing instruction -- <?xml version="1.0" ?>. External DTD is a reference to an external definition like the one below.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


blog comments powered by Disqus
XML ARTICLES

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials