Back
Next
If you have an idea about the HTML then the XML syntax shouldn't be
that much of a hurdle to grip. While there are a couple new items in XML,
it is still just a markup language that relies on some tags to get the mission done.
It is very important to understand that XML was basically designed to work with
data like data sending, receiving, processing etc. XML is not design to display
what it contains.
XML Document Structure.
<?xml version="1.0" encoding="ISO-8859-15"?>
<globalGuideLine>
<employee>
<FirstName>Austin</FirstName>
<gender>m</gender>
</employee>
<employee>
<FirstName>Angela</FirstName>
<gender>f</gender>
</employee>
</globalGuideLine>
If we spend a few moments reading the above XML example
we can see it has two employees: Austin and Angela record. This simple XML
document readily displays the benefits of XML. The data seems to almost describe
itself, which is one of the main reasons for XML being created.
Let's take a look at XML syntax by looking at the different parts of this
document. Note: This is just an overview of XML's syntax and there are links
to more information provided in this section of XML Tutorial.
<?xml version="1.0" encoding="ISO-8859-15"?>
The
above line of code will declare that this is an XML document. This line simply states what version of
XML we are using and the type of encoding we are using. Don't worry too much about this line,
just always include it exactly as we have above. Because it the acknowledgment
of a document as an XML document. If you are snooping, feel free to learn more about ISO 8859
on W3C.
Now step up and look at the XML Syntax, the first
<globalGuideLine> tag is the root tag for the entire XML document.
Remember that an XML document always be in single root element and that's why we
define this
<globalGuideLine> tag as the root of the entire XML document. All
the other elements will be appended in it and the term child element will be use
for other tags.
A new convention in XML Syntax will be this that all the element must be nested
properly. If you have learned the HTML then you know that there is no
strict rule to close HTML tags as they opened or suppose we do not close a tag in
HTML then it may not be found as an error. But in XML Syntax we must close
all elements properly as thy opened. Look at the above example we opened
the first employee element then we close it before opening the next one's.
Closing Convention of XML Elements.
Invalid XML Tags Closing Order.
<?xml version="1.0" encoding="ISO-8859-15"?>
<globalGuideLine>
<employee>
<FirstName>Austin</FirstName>
<gender>m
</employee>
<employee>
<FirstName>Angela<gender>f</FirstName>
</gender>
</employee>
</GlobalGuideLine>
Valid XML Tags Closing Order.
<?xml version="1.0" encoding="ISO-8859-15"?>
<globalGuideLine>
<employee>
<FirstName>Austin</FirstName>
<gender>m</gender>
</employee>
<employee>
<FirstName>Angela</FirstName>
<gender>f</gender>
</employee>
</globalGuideLine>
Explanation of XML Tags Closing Order:
On above examples as we see on first XML Syntax the root
element of <globalGuideLine> when started it is not ended with the same
prefix or syntax mean in XML syntax <globalGuideLine> and
</GlobalGuideLine> are not equal and in second exaple the root is proper
closed as its opening element is
<globalGuideLine> and closing
</globalGuideLine> are same. Second error on first example is that
the <gender> element is not close in HTML it may not be treated as error but in
XML we must close all tags proper. The third error in the first example
is that the <gender> element is nested in <FirstName> but its closing is
not proper. If we open <gender> as child of <FirstName> then we
must close it also in the tag of <FirstName> like <FirstName>Angela<gender>f</gender></FirstName>.
Back
Next
|