Posts in current category
May 27, 2021 17:00 XML
XML's syntax rules are simple and logical. These rules are easy to learn and easy to use.
In HTML, some elements do not have to have a close label:
<p>This is a paragraph. <br>
In XML, it is illegal to omit a closed label. All elements must have a close label:
"1.0" encoding="UTF-8" xml version=
<p>This is a paragraph.</p>
Note: From the example above, you may have noticed that the first line of XML declares that the label is not closed, that this is not an error, that the declaration is not part of the XML document itself, and that it does not close the label.
XML tags are case sensitive. The label is different from the label slt;message.
You must use the same case to write open and close labels:
<Message>This is incorrect</message> <message>This is correct</message>
Note: Opening and closing labels are often referred to as start and end labels. No matter what term you like, they all have the same concept.
In HTML, you often see elements that are not nested correctly:
<b><i>This text is bold and italic</b></i>
In XML, all elements must nest correctly with each other:
<b><i>This text is bold and italic</i></b>
In the example above, the correct nesting means that since the element is opened within the element, it must be closed within the element.
The XML document must have an element that is the parent of all other elements. This element is called the root element.
<root> <child> <subchild>.....</subchild> </child> </root>
Similar to HTML, XML elements can also have properties (pairs of names/values).
In XML, the property values of XML must be quoted.
Look at the following two XML documents. The first is wrong and the second is correct:
<note date=12/11/2007> <to>Tove</to> <from>Jani</from> </note>
<note date="12/11/2007"> <to>Tove</to> <from>Jani</from> </note>
The error in the first document is that the date property in the note element is not quoted.
In XML, some characters have a special meaning.
An error occurs if you place the character "lt;" in an XML element because the parser treats it as the beginning of a new element.
This results in an XML error:
<message>if salary < 1000 then</message>
To avoid this error, replace the character with an entity reference instead of the word ""
In XML, there are five predefined entity references:
Note: In XML, only the characters """"" A larger sign is legal, but it is a good practice to replace it with an entity reference.
The syntax of writing comments in XML is similar to the syntax of HTML.
<!-- This is a comment -->
Tip: You can also learn about "HTML slt;!--...-- and Comment Labels".
HTML cuts (merges) multiple consecutive space characters into one:
In XML, spaces in a document are not deleted.
In Windows applications, line breaks are typically stored in a pair of characters: carriage return (CR) and line break (LF).
In Unix and Mac OSX, LF is used to store new rows.
In older Mac systems, CR is used to store new rows.
XML stores line-overs in LF.
These are the syntax rules you need to be aware of when using XML, and write the correct XML documentation according to those rules!