Chapter 33. XML Reference

Table of Contents
33.1. DTD and Validation
33.2. Basic Elements
33.3. Scene
33.4. Atmosphere
33.5. Platform
33.6. Platform Motion
33.7. Task List

33.1. DTD and Validation

33.1.1. DTD

To ensure validity in your XML file, a document type definition (DTD) is used to provide a guideline for describing the syntax and grammatical structure of the file's content. It allows you to create your own markup language: new elements and attributes can be defined from scratch that best fit the information you want to encapsulate. The process of formally defining a language in XML is called document modeling. The DTD is one form of document modeling. It makes it possible to determine whether or not an XML document conforms to the document type. We'll use it to validate DIRSIG's XML input files.

A DTD can be declared inline in your XML document, or it can be referenced externally. We will use the external reference approach. The following XML example illustrates the content of DIRSIG's platform motion description, in which the DTD is externally referenced at the start of the description via the <DOCTYPE> tag. Our content is expected to conform to the DTD pointed to by the SYSTEM's uniform resource identifier.

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE platformmotion SYSTEM "http://www.cis.rit.edu/~pxlpci/dtd/platformmotion.dtd">

      <platformmotion type="generic" >
	  <method type="raw" />
	  <uncertainty enabled="0" >
	      <xlocation type="normal" >
		  <variance>0.00</variance>
	      </xlocation>
	      <ylocation type="normal" >
		  <variance>0.00</variance>
	      </ylocation>
	      <zlocation type="normal" >
		  <variance>0.00</variance>
	      </zlocation>
	  </uncertainty>
	  <data rotationorder="zyx" spatialunits="meters" angletype="absolute" angularunits="radians" >
	      <entry>
		  <datetime type="relative" >0.00</datetime>
		  <xlocation>243.84</xlocation>
		  <ylocation>243.84</ylocation>
		  <zlocation>304.80</zlocation>
		  <xrotation>0.00</xrotation>
		  <yrotation>0.00</yrotation>
		  <zrotation>0.00</zrotation>
	      </entry>
	  </data>
      </platformmotion>
	

The DTD associated with the aforementioned platform motion description would look like this:

      <?xml version="1.0" encoding="UTF-8"?>

      <!ELEMENT platformmotion          (method, uncertainty, data)>
      <!ATTLIST platformmotion          type (generic) #REQUIRED>

	  <!ELEMENT method              EMPTY>
	  <!ATTLIST method              type (raw) #REQUIRED>

	  <!ELEMENT uncertainty         (xlocation, ylocation, zlocation)>
	  <!ATTLIST uncertainty         enabled (0|1) #REQUIRED>

	      <!ELEMENT xlocation       (#PCDATA|variance)*>
	      <!ATTLIST xlocation       type CDATA #IMPLIED>

		  <!ELEMENT variance    (#PCDATA)>

	      <!ELEMENT ylocation       (#PCDATA|variance)*>
	      <!ATTLIST ylocation       type CDATA #IMPLIED>

	      <!ELEMENT zlocation       (#PCDATA|variance)*>
	      <!ATTLIST zlocation       type CDATA #IMPLIED>

	  <!ELEMENT data                (entry+)>
	  <!ATTLIST data                rotationorder CDATA #REQUIRED
					spatialunits (meters) #REQUIRED
					angletype (absolute) #REQUIRED
					angularunits (radians) #REQUIRED>

	      <!ELEMENT entry           (datetime, xlocation, ylocation, zlocation, 
					xrotation, yrotation, zrotation)>

		  <!ELEMENT datetime    (#PCDATA)>
		  <!ATTLIST datetime    type (absolute|relative) #REQUIRED>

		  <!ELEMENT xrotation   (#PCDATA)>

		  <!ELEMENT yrotation   (#PCDATA)>

		  <!ELEMENT zrotation   (#PCDATA)>
	  

33.1.2. Validating the XML File

33.1.2.1. Unix Shell-based Method

The free tool xmllint, found in most UNIX-like operating systems such as Linux and Mac OS X, is very handy for checking an XML file for errors. It reports very descriptive error messages (mismatched start/end tags, missing characters, etc.) and points out where the errors are. It can also be used to indent and "pretty print" a well-formed XML document.

For example, to validate an XML file named dirsig.xml, open up a terminal window and change into the directory where the file resides. Then type the following command after the shell prompt and press the return key:

      prompt> xmllint --valid --noout dirsig.xml
      

If the file doesn't conform to the DTD, you will receive subsequent error messages along with the file line number where the error occurred. Otherwise, you should see no output.

33.1.2.2. Web-based Method

There are also numerous websites which offer free XML validation checks, such as: http://www.xmlvalidation.com.