XML Syntax Rules



XML
Syntax Rules


The syntax rules of XML
are very simple and logical. The rules are easy to learn, and easy to use.


1.     All XML Elements Must Have a Closing
Tag


In
XML, it is illegal to omit the closing tag. All elements must have a
closing tag:



<p>This is a paragraph</p>

<p>This is another paragraph</p>


 


2.     XML Tags are Case Sensitive


XML tags are case sensitive. The tag <Letter> is
different from the tag <letter>.


3.     XML Elements Must be Properly Nested


In
XML, all elements must be properly nested within each other:



<b><i>This text is bold
and italic</i></b>


 


4.     XML Documents Must Have a Root
Element


XML
documents must contain one element that is the parent of all other
elements. This element is called the root element.



<root>

  <child>

    <subchild>.....</subchild>

  </child>

</root>


 


5.     XML Attribute Values Must be Quoted


<note date="12/11/2007">

  <to>Tove</to>

  <from>Jani</from>

</note>


6.     Entity References


Some characters have a
special meaning in XML.


If you place a character
like "<" inside an XML element, it 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
:



<message>if salary &lt; 1000
then</message>


There
are 5 predefined entity references in XML:



&lt;



less than


&gt;



greater than


&amp;


&


ampersand 


&apos;


'


apostrophe


&quot;


"


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.


 


7.     Comments in XML


The syntax for writing
comments in XML is similar to that of HTML.


<!-- This is a comment
-->


 


8.     White-space is Preserved in XML


HTML
truncates multiple white-space characters to one single white-space:



HTML:


Hello      
    Tove


Output:


Hello Tove


With
XML, the white-space in a document is not truncated.


 


9.     XML Stores New Line as LF


In Windows applications, a
new line is normally stored as a pair of characters: carriage return (CR) and
line feed (LF). In Unix applications, a new line is normally stored as a LF
character. Macintosh applications also use an LF to store a new line.


XML stores a new line as
LF.


 


hildren:
<title>,< author>, <year>, <price>.


for more info go to : http://www.w3schools.com/xml/

Comments

Popular posts from this blog

IrfanView : Simple Windows graphic viewer

MySQL Cluster Overview