creating XML Documents

Creating XML Documents

Creating XML Documents – You must now use these components to create a well-formed XML document, which conforms to the XML standards and syntax rules 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 <LI> of HTML to create list items:

<LI> This is the first bulleted item.

<LI>This is the second bulleted item

In this code snippet, the <LI> 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:

<LI> This is the first bulleted item.</LI>

<LI>This is the second bulleted item.<LI>

In the preceding example, the beginning and end tags are clearly specified. Therefore, the LI elements created in the example conform to the rule of well-formed document.


In the preceding example, the LI element in the XML will not produce a bulleted list in the output. This is because unlike HTML, XML does not have predefined tags. It is also not used to produce formatted output.

  • Empty tags must be closed using a forward slash (/). Empty tags do not contain any information. However, they can contain attributes. The values of these attributes are specified within the opening and closing angular brackets of the empty tag. This tag must contain a forward slash (/) that precedes the closing angular bracket. Consider the following example:


< PICTURE name=”mypicture.gif”/>

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

  • All attribute values must be given in the 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:

<FONT size”12”>

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

  • Tags must have proper nesting. In XML, opening tags 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:

<AUTHOR > john Grisham <BOOKNAME> The Client </AUTHOR> </BOOKNAME>

In this example, the sequences in which the opening tags are closed are invalid, because the outer tags, AUTHOR, is closed before the inner tag, BOOKNAME. The correct sequence would be:

<AUTHOR> John Grisham <BOOKNAME> The client </BOOKNAME></AUTHOR>

  • XML tags are case-sensitive .The opening and closing tags must correspond in every respect. Any difference between the opening and closing tags would result in an error in this code. Consider the following line of code.

<PRICE> 250</price>

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


Leave a Reply

Your email address will not be published.