Why does an XML declaration starts with "<?xml" instead of "<!xml"?
I thought X开发者_运维百科ML is an application of SGML, and that the default syntax for an SGML declaration starts with "<!"
delimiter.
Based on that understanding, I'm not clear how "<?"
comes about.
Would someone please cxplain? Thank you.
The <!
begins a DOCTYPE declaration, and <?
begins a processing instruction. The <?xml
processing instruction is specified by the standard to indicate that what follows is XML, indicate the version of XML and the text encoding. It has no relationship to the actual structure of the document, which is something the DOCTYPE declaration would. I'm not sure why the DOCTYPE declaration is specified differently than a processing instruction, but a lot (maybe most) XML documents these days have their structure defined by XML schema or RelaxNG instead, and only a DTD can be referenced from the DOCTYPE. There are other ways to use processing instructions; mostly they were introduced to provide vendors with a side entrance for their own features. Probably the second most common use is for linking to XSLT or CSS stylesheets.
XML was originally conceived as a simplified subset of SGML, but since then it has become much more different. It wouldn't really be fair to say XML "is" SGML anymore in any sense, just that they are related by history and genealogy.
精彩评论