XML declaration example
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes"?>
XML document can optionally have an XML declaration. XML document without declaration is also valid
<student>
   <name>George</name>
   <city>Tbilisi</city>
   <phone>(011) 123-4567</phone>
</student>
If the XML declaration is included, it must contain version number attribute
<?xml encoding="UTF-8" standalone="no"?>
<student>
   <name>George</name>
   <city>Tbilisi</city>
   <phone>(011) 123-4567</phone>
</student>
It will generate the following error:
error on line 1 at column 7: Malformed declaration expecting version
The names are always in lower case
<?xml Version="1.0" encoding="UTF-8" standalone="no"?>
<student>
   <name>George</name>
   <city>Tbilisi</city>
   <phone>(011) 123-4567</phone>
</student>
It will generate the following error:
error on line 1 at column 7: Malformed declaration expecting version
The XML declaration must begin with
<?xml
<? version="1.0" encoding="UTF-8" standalone="no"?>
<student>
   <name>George</name>
   <city>Tbilisi</city>
   <phone>(011) 123-4567</phone>
</student>
The following error will be generated:
error on line 1 at column 3: xmlParsePI : no target name
If document contains XML declaration, it must be the
first statement
<student>
   <name>George</name>
   <city>Tbilisi</city>
   <phone>(011) 123-4567</phone>
</student>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
The error will be the following:
error on line 6 at column 6: XML declaration allowed only at the start of the document
The order of placing the parameters is important. The correct order is:
version
,
encoding
and
standalone
<?xml encoding="UTF-8" standalone="no" version="1.0"?>
<student>
   <name>George</name>
   <city>Tbilisi</city>
   <phone>(011) 123-4567</phone>
</student>
This will generate the following error:
error on line 1 at column 7: Malformed declaration expecting version
Either single or double quotes may be used. Here is valid XML document
<?xml version='1.0' encoding='UTF-8' standalone="no"?>
<student>
   <name>George</name>
   <city>Tbilisi</city>
   <phone>(011) 123-4567</phone>
</student>
An HTTP protocol can override the value of encoding that we put in the declaration.
by Valeri Tandilashvili
4 years ago
XML
XML Tutorial
0
Pro tip: use ```triple backticks around text``` to write in code fences