LISA 2003, San Diego
Search for Validation
•<!DOCTYPE etc_passwd [
•<!ELEMENT etc_passwd (pw_entry)*>
•<!ELEMENT pw_entry (username, unixuid, gid, gecos?, homedir?, shell?, person_id?, user_type)>
•<!ATTLIST pw_entry platform CDATA #REQUIRED>
•<!ELEMENT username (#PCDATA) >
•<!ELEMENT unixuid (#PCDATA) >
•<!ELEMENT gid (#PCDATA) >
•<!ELEMENT gecos (#PCDATA)>
•<!ELEMENT homedir (#PCDATA)>
•<!ELEMENT shell (#PCDATA)>
•<!ELEMENT person_id (#PCDATA)>
•<!ELEMENT user_type (#PCDATA) >
•
One very nice feature of XML, is the option for a Data Type Definition (DTD) or Schema.  This allows you to define what fields and elements are allowed in an XML document.  With this, there are a number of tool available to let you validate your XML to ensure that it is syntactically correct.  If you are generating XML, or even hand writing it, this will let you check it before you pass it along to the destination.  And if you are writing something that will process XML, this can help you understand what to expect when you get it.

In this example here, we have the DTD for the /etc/passwd example.

• (CLICK) It shows how document etc_passwd is made up of a number of pw_entry elements.  The asterisk indicates that we want 0 or more entries.
•(CLICK) Each pw_entry elements has some require fields, username, unixuid, gid and user_type,
•(CLICK) and some optional fields indicated with the question mark.
•(CLICK) In addition, each pw_entry element has a required attribute of platform.
•(CLICK) And finally, you have to define the data type of all the individual elements.