Sams Teach Yourself XML in 21 Days

Sams Teach Yourself XML in 21 Days

By Steven Holzner

Creating Processing Instructions

As you can gather from their names, processing instructions are instructions to the XML processor, not general data-handling items like elements. XML doesn't come with any processing instructions built-in; it's up to your XML processor to support the ones it uses. For example, a common processing instruction is <?xml-stylesheet?> (supported by browsers like Netscape Navigator and Internet Explorer), but that's not an official W3C processing instruction built into XML. In other words, processing instructions must be understood by the XML processor, so they're processor-dependent.

Processing instructions start with <? and end with ?>. The only restriction here is that you can't use <?xml?> (or <?XML?>, which is also reserved). We saw an example processing instruction yesterday in ch01_03.xml, where we used <?xml-stylesheet?> to connect a CSS style sheet to that XML document:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="ch01_04.css"?>
<document>
    <heading>
        Hello From XML
    </heading>
    <message>
        This is an XML document!
    </message>
</document>

Keep in mind that processing instructions like this one are not built into XML, but have been agreed upon by various browser manufacturers.

Now we've seen all that an XML prolog can contain, except for DTDs: XML declarations, comments, processing instructions, and whitespace. Next up is the actual meat of XML documents—storing your data using tags and elements.

Share ThisShare This

Informit Network