What is <?xml version=“1.0”?>?

*爱你&永不变心* 提交于 2020-01-11 08:52:07

问题


What is the difference between

<?xml version="1.0"?>

and

<xml version="1.0">

Why does it look like shorthand PHP in the XML tag? I'm sure that's what it is but why is it there?

I have an XML file that is throwing an error, but I couldn't find the error and now I'm assuming it's the ? in the XML tag?


回答1:


<?xml version="1.0"?> is an XML declaration. It is an optional indication of the version of XML, the character encoding, and the standalone document declaration. It can only appear as the very top of an XML file, if anywhere, and may not be repeated.

<xml version="1.0"> is an open tag (that will require a closing tag) to an XML element. While it would be well-formed (if properly closed), do not use this -- it looks too much like an bungled XML declaration. Moreover, the W3C XML Recommendation states:

Names beginning with the string "xml", or with any string which would match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization in this or future versions of this specification.



来源:https://stackoverflow.com/questions/45380229/what-is-xml-version-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!