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.
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.
XML Pro recognizes two types of DTD errors:
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.
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.
Figure 3-1. Associate DTD dialog box
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.
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:
The Public field corresponds to the value of the Public attribute in the DOCTYPE element that defines the DTD associated with the document.
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.
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.
PCDATA can be added to a document by right clicking on the insertion point, and selecting Add PCDATA from the Pop-up Menu.
There are two ways to remove 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.
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.
CDATA can be added by right clicking on the insertion point, and selecting Add CDATA from the Pop-up Menu.
There are two ways to delete CDATA:
Once CDATA is removed and the document is saved, the deleted CDATA is no longer available.
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.
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.
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.