开发者

Why does an XML declaration starts with "<?xml" instead of "<!xml"?

开发者 https://www.devze.com 2023-03-21 05:53 出处:网络
I thought X开发者_运维百科ML is an application of SGML, and that the default syntax for an SGML declaration starts with \"<!\" delimiter.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号