Syntax of An XML Element

In this article I have described about the syntax of XML application with the help of example .
  • 1827

XML SYNTAX 

XML is a language used to describe and manipulate structured documents. XML is a flexible mechanism that accommodates the structure of specific applications.

A Simple XML Document

<?xml version="1.0" encoding="UTF-8" ?>
<greeting>WELCOME TO MCN</greeting>

A Simple XML Document with internal DTD

<?xml version="1.0" encoding="UTF-8" ?>
<!-- This document is valid -->
<!DOCTYPE greeting [<!ELEMENT greeting (#PCDATA)>]>
<greeting>HWELCOME TO MCN</greeting>

A Simple XML Document with external DTD , Comment & PI

<?xml version="1.0" encoding="UTF-8" ?>
<!-- Here is a procession instruction -->
<?render bold ?>
<!DOCTYPE greeting SYSTEM "MCN.dtd">
<greeting>WELCOME TO MCN</greeting>

SYNTAX RULE

There are some basic and important rule for XML syntax are as follows

  1.  All XML elements have a closing tag.

          e.g.   
    <b>Welcom to MCN</b>
     
  2. All XML Elements should be properly nested.

          e.g.   
    <b><i>This text is bold and italic</i></b>
     
  3. Xml tags are case sensitive.

          e.g.    
    <message>Welcom to mcn</message>
     
  4. With XML, the white-space in a document is not truncated .White-space is Preserved in XML while not so in HTML.
     
  5. XML Documents Must Have a Root Element

        e.g.  
    <root>
                           <child>
                              <subchild>.....</subchild>
                           </child>
                        </root>

     
  6. XML Attribute Values Must be Quoted .

           e.g.  
    <note date="04/05/2012">
                    <to>ajay</to>
                    <from>gaurav</from>
                   </note>
     
  7.  XML Stores New Line as LF.
     
  8. Comments in XML is same as in HTML as

           <!-- This is a comment -->

Further Readings

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2019 DotNetHeaven. All rights reserved.