Reputation: 325
Having pored over the XML W3C Recommendation 1.0, I'm still confused regarding the general nature of the
<!FOO ...>
type tags. What is the rationale behind these tags, how are they parsed, and are there any generalizations to this syntax. To me they seem like an almost ad hoc hack added to XML in order to facilitate stuff which wasn't thought of when XML was first designed... Are the valid
<! > and <![ ]> (like <!DOCTYPE ...> and <![CDATA []]>)
tags hardwired into the XML standard, or can I define my own? If so, how do they get parsed? I'm just asking because I would like to get a complete picture of XML, not because it would be useful ;)
Regards,
Jonas
Upvotes: 3
Views: 174
Reputation: 169693
<!…>
sections contain XML-specific processing instructions, and are - in contrast to the general processing instructions <?…?>
- hardwired into the standard.
If you're interested in where the syntax comes from, you should look into SGML, which is a superset of XML predating it by a decade.
Upvotes: 1
Reputation: 29029
These kinds of tags[footnote] are hardwired; and pretty much only include comments, CDATA
and DOCTYPE
; both of which are holdovers from SGML.
Something similar exists in <?name ?>
style tags, which can be user-defined (with the exception of <?xml* ?>
, and are called Processing Instructions.
The use of these should be limited (as should the use of <!
tags; including DOCTYPE and CDATA), if not non-existent (with the obvious exception of comments (<!--
) and the XML declaration (<?xml
)).
In certain highly specific applications, of course, Processing Instructions are perfectly legitimate (PHP entry/exit tags (<?php ?>
) could be considered processing instructions, but PHP isn't PXP, and doesn't obey the rules for where PIs can legally be (hint: you can't have PIs in attributes and inside of tags).
Generally speaking: Don't use processing instructions unless you are planning on preprocessing the XML. Like CDATA
and DOCTYPE
, they aren't meant to convey information, but to tell a (pre-)processor how to (pre-)process the XML before/while parsing it.
Footnote: <! >
style instructions aren't actually tags; they are comments, doctypes and CDATA sections. If there is a name for these three constructs together, it escapes me at present.
Upvotes: 3