3. DOCUMENT TYPE DEFINITION, PCDATA, CDATA & COMMENTS

This chapter describes how XML Pro handles other important XML features: Document Type Definition (DTD) files, PCDATA, CDATA, and comments. Document Type Definition files describe what an XML file will look like. PCDATA is 'parsed' character data, CDATA represents character data other than what is already described by entities and attributes. Comments are simply additional remarks about an element.

3.1 Validation

Documents can be validated (conforms to a DTD) by selecting Validate from the Tools menu, or clicking the Validate button on the toolbar. The current XML document contents are checked against the constraints specified in the associated DTD, to ensure that the document format and content conforms to the DTD specifications.

If XML Pro encounters an error during the process, an error message is generated, similar to this:

Invalid element 'PARTNUM' in content of weight. Expected [PCDATA]

The message indicates the error encountered, and XML Pro highlights the item that generated the error in the document tree view. The validation process stops when an error is generated, so you should correct the error. Once it has been corrected, try validating the document again, and repeat this process until validation is successful with no error messages displayed.


3.1.1 DTD Errors

XML Pro recognizes two types of DTD errors:

  1. A missing DTD. If XML Pro cannot find the associated DTD, an error is generated, and the XML file will not load.
  2. DTD syntax errors. If XML Pro is unable to correctly parse the associated DTD due to an error in the DTD file, an error message is generated, similar to the one below:

Error opening document: Expected DOCTYPE instead of Entity At line 2

The error message will indicate what the error is (if possible), and give a line number, so the DTD can be corrected.


3.1.2 Handling Invalid Documents

XML Pro will open documents which have an associated DTD, but which are invalid. XML Pro will not open an XML document that is not well-formed. When opening a document that is invalid, XML Pro generates an error message indicating the problem. The problem should be corrected, and the document successfully validated before editing the document within XML Pro.

NOTE: Well-formed means that all tags (elements) in the document match, all attribute values match and all entities for the element are declared.

XML Pro allows invalid documents to be saved, but first prompts you to make sure you are aware the document has not been validated.

Associate DTD Dialog Box

Figure 3-1. Associate DTD dialog box


[<back>]
[back to TOC]

3.2 Naming the DTD

The Name field in the Associate DTD dialog is not user-definable. In accordance with the XML 1.0 Specification, the "name" of the associated DTD actually corresponds to the DOCTYPE (the document type declaration) in the tag which specifies the DTD association in the XML file. This DOCTYPE must match the name of the root element in your document, so this will be determined automatically.


[<back>]
[back to TOC]

3.3 The DTD Location

DTD location is specified in the System text field. This is to correspond with the convention for specifying the location of DTD's within the XML document itself. The location can be:


  1. A file name. The DTD and XML document must occupy the same directory.
  2. A file URL. You must use the "file:/" descriptor, and provide the full path to the location of the DTD.
  3. A WWW URL. For example, "http://www.myserver.com/mydtd.dtd."

3.3.1 The Public String

The Public field corresponds to the value of the Public attribute in the DOCTYPE element that defines the DTD associated with the document.


[<back>]
[back to TOC]

3.4 Removing an Association

To remove a DTD association, open the Associate DTD dialog and click the Remove button.

NOTE: Any changes made to the DTD Association will not take effect until the document is saved and reloaded.


[<back>]
[back to TOC]

3.5 PCDATA

XML Pro supports viewing PCDATA items as icons in the tree view, letting you see the overall document structure more easily. XML Pro lets you add and/or delete PCDATA.


3.5.1 Adding PCDATA

PCDATA can be added to a document by right clicking on the insertion point, and selecting Add PCDATA from the Pop-up Menu.


3.5.2 Removing PCDATA

There are two ways to remove PCDATA:

  1. Right click on the PCDATA you wish to remove, and select Delete.
  2. Select the PCDATA you wish to remove, and select Delete Element from the Tools menu. Once PCDATA is removed and the document is saved, the deleted PCDATA is no longer available.

3.5.3 Editing PCDATA

To edit PCDATA, click on it. This loads the content into the Text Editing pane of the editor, where you can type additional text, or cut, copy and paste text and information into the PCDATA.


[<back>]
[back to TOC]

3.6 CDATA

CDATA can be any kind of character data, other than elements, entities or attributes. CDATA is represented in the document tree with the CDATA icon and label, and the contents of the CDATA element are not shown in the tree. Once a CDATA item has been added to the tree, the contents can be edited in the Text Editing pane of the main window. XML Pro lets you add and/or delete CDATA.


3.6.1 Adding CDATA

CDATA can be added by right clicking on the insertion point, and selecting Add CDATA from the Pop-up Menu.


3.6.2 Deleting CDATA

There are two ways to delete CDATA:

  1. Right click on the CDATA you wish to delete, and select Delete.
  2. Select the CDATA you wish to delete, and select Delete Element from the Tools menu.

Once CDATA is removed and the document is saved, the deleted CDATA is no longer available.


[<back>]
[back to TOC]

3.7 Comments

XML Pro also supports XML comments. XML comments are represented in the document tree with the Comment Icon and Label. A comment's contents can be edited in the main window Text Editing pane.


3.7.1 Adding Comments

Comments can be added to a document by clicking the right mouse button on the insertion point, and then selecting Add Comment from the Pop-up Menu.


3.7.2 Removing Comments

There are two ways to remove a Comment:

Like CDATA and PCDATA, once a Comment is removed and the document saved, it no longer is available.


[<back>]
[back to TOC]