.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Articles >> XML >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Identifying the rules for creating XML document

Posted By:Ravi Ranjan Kumar       Posted Date: November 30, 2011    Points: 200    Category: XML    URL: http://www.dotnetspark.com  

This article enable you to understand the basics rules for creating XMl document.

It's suggested that before reading this article you need to know the basic concept of an XML document. You need to create a well-formed XML document, which confirms to the XML standards and Syntax rules specified by W3C.

The rules that govern the creation of a well-formed XML document are :- 

a) Every Start tag must have an end tag. Tags cannot be inferred. They must be explicitly specified. Every XML document must have a root element that contains all other elements used in the document. 
Consider the following example that uses the
  • tag of HTML to create list items :

  • This is the first bulleted item
  • This is the second bulleted item
  • In this code snippet the
  • tag marks the beginning of a bulleted list. It has a start tag but doesn't have an end tag. Therefore, this tag marks the beginning of a new list item and also indicates the end of the previous list item. XML does not allow such ambiguity. The Same tag must be used in XML as:

  • This is the first bulleted item
  • This is the second bulleted item

  • In the preceding example, the beginning and end tag are clearly specified. Therefor the LI elements created in the example conform to the rules of well-formed document.

    b) Empty tagmust be closed using a forward slash(/). Empty tag don't contain any information. However, they can contain attributes. The values of these attributes are specified within the opening and closing angular bracktes of the empty tag. This tag must forward slash(/) that precedes the closing angular bracket. Consider the following example :

    In the preceding example, picture is an empty element that contains an attribute called name. The values of this attribute are set to the name of a picture file.

    c) All attribute values must be given in double quotation marks. Unlike HTML,XML does not allow the value of an attribute to be specified outside the double quotation marks

    Consider the following statement :

    In the preceding statement, the size attribute of the font element takes a value 12

    d) Tags must have proper nesting, in XML, operating tag must be closed  in the reverse order in which they appear, that is the innermost tags must be closed before the outer tags.

    Consider the following example :

    Prem ChandGodan

    In this example, the sequence in which the opening tags are closed is invalid, because the outer tag, Author is closed before the inner tag, BookName. The Correct sequence would be

    Prem ChandGodan
     e) XML tags are case-sensitive. The Opening and closing tags must correspond in every respect. Any differences between the opening and closing tags would result in an error in the code. Consider the following line of code :


    The preceding line of codes will not display the dsired output as the opeing and closing tags are written in different cases. The correct code is :


     Subscribe to Articles


    Further Readings:


    No response found. Be the first to respond this post

    Post Comment

    You must Sign In To post reply
    Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend