Web Services, Part VIII: Reading DTDs with JavaScript: Defining XML File Structure - Doc JavaScript | WebReference

Web Services, Part VIII: Reading DTDs with JavaScript: Defining XML File Structure - Doc JavaScript


Web Services, Part VIII: Reading DTDs with JavaScript

Defining XML File Structure

The DTD file contains several types of declarations. First, it includes declarations about the XML document structure. You need to specify each element's content. The root element sales, (see page 2 for a listing of our mydvd XML file), includes the elements summary and data:

<!ELEMENT sales (summary, data)>

Be sure to put all child elements within parentheses and separated by commas. The summary element includes the following elements: heading, subhead, description, author, and date:

<!ELEMENT summary (heading, subhead, description, author, date)>

The data element includes one or more elements of month. You specify repetition with an asterisk:

<!ELEMENT data (month*)>

The month element consists of two elements: name and week (one or more instances):

<!ELEMENT month (name, week*)>

We have reached leaf cells in our XML tree structure. Leaf-cell elements do not include elements but are pure Parsed Character Data (PCDATA). You define their content as (#PCDATA):

<!ELEMENT heading (#PCDATA)>
<!ELEMENT subhead (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT week (#PCDATA)>

The DTD should also include definitions of the element attributes. The syntax of ATTLIST is quite complicated. In our mydvd XML file, week has two attributes, number and dvds_rented. They are character data (CDATA) and required (#REQUIRED). Here are the definitions of these two attributes:

<!ATTLIST week number CDATA #REQUIRED>
<!ATTLIST week dvds_rented CDATA #REQUIRED>

Next: How to define entity references

https://www.internet.com


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: February 11, 2002
Revised: February 11, 2002

URL: https://www.webreference.com/js/column103/3.html