Item 17. Use Processing Instructions for Process-Specific ContentProcessing instructions are certainly useful, but they can be a source of interoperability problems. They are not normally validated , and many processes ignore them by default. SOAP, the Extensible Messaging and Presence Protocol (XMPP), and a few other applications have even chosen to forbid them (in violation of Item 14, I'll note). Be careful not to use processing instructions for information that really deserves to be part of the markup instead. The correct purpose of processing instructions is, naturally enough, to give instructions to particular processes that read the XML document. The following characteristics normally indicate that a processing instruction is warranted.
When are processing instructions not appropriate? I can think of two main criteria:
In both cases, processing instructions are being used as a sort of pseudo-tag. This sidesteps the normal XML parsing and validation process and eliminates some of the customary benefits of XML. Let's explore these criteria by investigating common usages of processing instructions, both good and bad. |