Simple XML Rules

If you are familiar with HTML, then there are a few simple rules that differentiate XML from HTML:

■ Every data element has to begin and end with an identical tag. Tag names are case sensitive. <TagName>Data</Tagname> is not valid. <TagName>Data</TagName> is valid.

■ The XML file must begin and end with a root tag. There can be only one root tag in the file. In the example earlier, the root tag is <TodaysOrders>.

■ It is valid to have an empty tag. Put a slash at the end of the tag. If there is no zip code for an international order, for example, use <Zip/> to indicate that there is no data for this field for this record.

■ If you nest tags, the inner tag must be closed before you close the outer tag. This is different from HTML. In HTML it is valid to code <b>XML is very <i>cool</b></i>. This is not valid in XML. <Item><a>data</a></Item> will work, but <Item><a>data</Item></a> will not.

For a more thorough discussion of XML, see Benoit Marchal's XML by Example (0-78972504-5).

0 0

Post a comment