XML documents must contain one element that is the parent of all other elements. That element is called the root element.
Syntax:-
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
XML Attribute Values Must be Quoted.
XML elements can have attributes in name/value pairs just like in HTML. But in XML the attribute value must always be quoted. Study the two XML documents below. The first one is incorrect, the second is correct:
HTML --> <design style=bold>
XML ---> <design style="bold">
Some characters have a special meaning in XML.
If you place a character like "<" inside an XML element, for example:
<category> Mahi has < rs.10000 </category>
The character "<" will generate an error because the parser interprets it as the start of a new element. To avoid this error, replace the "<" character with an entity reference:
<category> Mahi has < rs.10000</category>
There are 5 predefined entity references in XML:
< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark
Note: Only the characters "<" and "&" are strictly illegal in XML. The greater than character is legal, but it is a good habit to replace it.
Comments in XML. The syntax for writing comments in XML is the same as in HTML.
<!-- This is a comment -->
In XML, White Space is Preserved. In an HTML file, multiple white space characters are reduced to a single white space. But in an XML file, the white space is not truncated.
Syntax:-
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
XML Attribute Values Must be Quoted.
XML elements can have attributes in name/value pairs just like in HTML. But in XML the attribute value must always be quoted. Study the two XML documents below. The first one is incorrect, the second is correct:
HTML --> <design style=bold>
XML ---> <design style="bold">
Some characters have a special meaning in XML.
If you place a character like "<" inside an XML element, for example:
<category> Mahi has < rs.10000 </category>
The character "<" will generate an error because the parser interprets it as the start of a new element. To avoid this error, replace the "<" character with an entity reference:
<category> Mahi has < rs.10000</category>
There are 5 predefined entity references in XML:
< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark
Note: Only the characters "<" and "&" are strictly illegal in XML. The greater than character is legal, but it is a good habit to replace it.
Comments in XML. The syntax for writing comments in XML is the same as in HTML.
<!-- This is a comment -->
In XML, White Space is Preserved. In an HTML file, multiple white space characters are reduced to a single white space. But in an XML file, the white space is not truncated.
No comments:
Post a Comment