Wednesday, October 10, 2012

XML Well Form


XML Well Form
For well formed XML we follow the following rules.
Well form talks about the structure of the xml document
Rules:
·         XML file should start with prolog (optional)
·         Only one root tag is allowed
·         All the elements (tags) must be under Root Tag only
·         Every stating tag must have ending tag (closing tag)
·         The level of opening tag must be closed the same level
·         XML tags are case sensitive  i.e <Tag> and <tag> both are treated as different tags
Demo:
File Name: Demo.xml
<?xml version="1.0" encoding="UTF-8"?>
<PURCHAGEORDER> <!- root tag opening at level 0 -->
                <ORDERITEMS> <!- opening tag at level 1 -->
                                <ITEM>  <!- opening tag at level 2 -->
                                                <ITEMCODE>NOKIA345</ITEMCODE>
                                                <QUANTITY>6</QUANTITY>
                                </ITEM><!- closing tag at level 2 -->
                </ORDERITEMS> <!- closing tag at level 1 -->
                <SHIPPINGADDRESS><!- opening tag at level 1 -->
                                <ADDR>SAN</ADDR><!- opening and closing tag at level 2 -->
                                <DORNO>77-98</DORNO><!- opening and closing tag at level 2 -->                                                                                                     <STREAT>GOPALNAGAR</STREAT><!- opening and closing tag at level 2 -->
                                <CITY>HYD</CITY><!- opening and closing tag at level 2 -->
                </SHIPPINGADDRESS><!- closing tag at level 1 -->
</PURCHAGEORDER><!- closing tag at level 0 -->

Note: above demo.xml file satisfy’s all the rules so its call well formed xml
1.     For checking is well formed or not open in the browser, if its shows the above content as it we wrote
Otherwise it shows the error where and what
2.     use the xml spy tool check whether the xml is well formed or not