The best XML Syntax Tutorial In 2024, In this tutorial you can learn All XML elements must have a closing tag,XML tags are case sensitive,XML must be properly nested,XML document must have a root element,XML attribute values must be quoted,Entity reference,XML comments in,In XML, the space will be reserved,XML is stored in LF line feed,
XML syntax rules are simple and very logical. These rules are easy to learn, and very easy to use.
In HTML, some elements do not have a closing tag:
In XML, omit closing tag is illegal. All elementsmust have a closing tag:
Note: From the above examples, you might have noticed that the XML declaration did not close the tab.This is not an error. Declaration is not part of the XML document itself, it has no closing tag.
XML tags are case sensitive. Tag <Letter> tag <letter> is different.
You must use the same case to write open and closing tags:
Note: Opening and closing tags are commonly referred to as the start and end tags.Whether you like what terms, their concepts are the same.
In HTML, you often see are not properly nested elements:
In XML, all elementsmust be properly nested within each other:
In the example above, the correct meaning is nested: Because <i> element within <b> element to open, then it must be closed in the <b> element.
XML document must have aelement is the parentof all other elements. This elementis called the root element.
Similar to HTML, XML elements can have attributes in (name / value pairs).
In XML, XML attribute values must be quoted.
Please study the following two XML documents. The first one is incorrect, the second is correct:
Error in the first document is, note the date property element is not quoted.
In XML, some characters have special significance.
If you put the character "<" on the XML element, an error occurs because the parser will use it as the beginning of a new element.
This will generate an XML error:
To avoid this error, please useentity references instead of "<" character:
In XML, there are 5 predefined entity references:
< | < | less than |
> | > | greater than |
& | & | ampersand |
' | ' | apostrophe |
" | " | quotation mark |
Note: In XML, only the characters "<" and "&" is indeed illegal.Greater than sign is legal, but using entity references instead it is a good habit.
Write a comment in XML syntax and HTML syntax is very similar.
<-! This is a comment ->
HTML will cut more than one consecutive space characters (merged) into one:
HTML: | Hello Tove |
Output: | Hello Tove |
In XML, a document spaces will not be deleted.
In Windows applications, a new line is usually used to store a pair of characters: carriage return (CR) and line feed (LF).
In Unix and Mac OSX, use LF to store a new line.
In the old Mac system, use CR to store the new row.
XML is stored in LF line feed.