Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is <?xml version="1.0"?>?

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?

like image 402
Singleton Avatar asked Jul 28 '17 18:07

Singleton


1 Answers

XML Declaration

<?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.

like image 108
kjhughes Avatar answered Oct 16 '22 10:10

kjhughes