<?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.XML Attribute specifies a single property for the element, using a name/value pair. An XML-element can have one or more attributes<a href = "http://www.applications.ge/">Applications.ge</a>In the example href is the attribute name and http://www.applications.ge is the attribute value
...
XML attribute names (unlike HTML) are case sensitive. Which means that HREF and href are considered two different XML attributes<?xml version="1.0"?>
<student>
<a href="http://www.applications.ge/" hreF="HTTP://applications.ge/">Applications.ge</a>
</student>
Several different values for the same attribute is not allowed. An attribute name must not appear more than once in the same tags:<?xml version="1.0"?>
<student>
<a href="http://www.applications.ge/" href="HTTP://applications.ge/">Applications.ge</a>
</student>The following error will appear on the browsererror on line 3 at column 73: Attribute href
redefined
Attribute names must always be defined without quotation marks, whereas attribute values must always appear in single or double quotation marks<?xml version="1.0"?>
<student>
<a "href"="http://www.applications.ge/">Applications.ge</a>
</student>The following error will appear:error on line 3 at column 8: error parsing attribute name
Attribute values must always be in quotation marks (single ' or double " quotes)<?xml version="1.0"?>
<student>
<a href=http://www.applications.ge/>Applications.ge</a>
</student>This incorrect syntax will generate the following error:error on line 3 at column 13: AttValue: " or ' expected< - less than - <
> - greater than - >
' - ampersand - &
" - apostrophe - '
& - quotation mark - "& which is a reserved character and end with the symbol ;
XML has two types of references:
...
1. Entity Reference − which contains a name between the start and the end delimiters.
For example & where amp is name. The name refers to & symbol.
...
2. Character Reference − contains reference, such as A contains a hash mark # followed by a number.
The number refers to the Unicode code of a character. In this case, 65 refers to alphabet Aversion - specifies the version used in the XML document (1.0)
encoding - defines the character encoding used in the XML document (UTF-8)
standalone - if the value is yes it means there is no external declaration required to parse the document (yes)case-sensitive - because of the case difference in two tags, which is treated as incorrect syntax in XML<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<student>
<name>George</name>
<city>Tbilisi</city>
<phone>(011) 123-4567</phone>
<address>Wrong syntax</ADdress>
<hr />
</student>This will generate the error:error on line 6 at column 23: Opening and ending tag mismatch: address line 0 and ADdress
XML tags must be closed in an appropriate order, which means an XML element opened inside another element must be closed before the outer element<outer_element>
<internal_element>
Right, because the inner tag is closed before the outer
</internal_element>
</outer_element><?xml version="1.0" encoding="UTF-8"?>
<student>
<name>George</name>
<phone>(011) 123-4567</phone>
<address></address>
<city />
</student>One way is <address></address> element and another is <city />. In other words, one with closing tag and another is self-closing tag.-, under-score _ and period . are allowed in element name. The XML example is valid<?xml version="1.0" encoding="UTF-8"?>
<student>
<first-name>George</first-name>
<phone.mobile>(011) 123-4567</phone.mobile>
<native_language>English</native_language>
<city />
</student>symbols in names are the hyphen -, under-score _, period . and digits 0-9
- Names are case sensitive, Address, address, and ADDRESS are different names.
- Start and end tags of an element must be the same.
- An element, which is a container, can contain text or elements <?xml version="1.0" encoding="UTF-8"?>
<student>
<first-name>George</first-name>
<phone.mobile>(011) 123-4567</phone.mobile>
<native_language>English</native_language>
<city />
</student>
Note: XML element name must not start with ., -, digit<!-- Our comment -->
XML comment example in XML document:<?xml version="1.0" encoding="UTF-8"?>
<student>
<!-- Some comment about the student -->
<first-name>George</first-name>
<phone.mobile>(011) 123-4567</phone.mobile>
<tive_language>English</tive_language>
<another_tag>some text</another_tag>
<city />
</student>