Crash course in Basic XML
Quick overview of what you can find at www.w3schools.com
What is XML?
Extensible Markup Language is a tag format similar to HTML that is if you were allowed to makeup your own tags. However, unlike HTML the purpose of XML is to store data in plain text files, so that it is transferred from platform to platform with ease. Just in case you were wondering HTML was designed to display data while XML was designed to store data.
If an XML document can have any tag how is it meaningful to anything?
Okay lost of ways to answer this, but basically XML is very free in form, but in most cases where it’s required the format is usually defined. The XML file’s schema defines how it should look with whatever elements; also there are a few standards you should have in a XML document. If you’re familiar with XML already don’t get upset, I know there are many other ways to define the structure of a XML document, I’m just no getting into them mainly since you can learn them on your own and this isn’t an in-depth explanation.
What is an element?
The short version is that an element is pretty much everything in between and including the tag; so if I had the tag <greeting>hello</greeting> in my document that would be considered an element. Now every document requires a root element, typically this would describe the data in the document as a whole; for example you want to create a score card to keep track of a tournament you’re root element could be something like this:
<code>
<! -- This is the root element -->
<scorecard>
<team>The Cookie Monsters</team>
<score round=”1”>12</score>
</scorecard>
</code>
This is also useful when creating XML documents that describe databases, but that’s for another day. Other child elements reside in the root element and describe/ store the data in the document.
What is an attribute?
Attributes are additional pieces of information that are stored within elements, these things typically describe single data values that could also be described in an element. These are stored in the start tag and there values must be in quotes, which can either be “” or ‘’. Here is an example: <data type=”string”>cookie?</data>.
Things to note:
- XML is case sensitive so the tags <Note> and <note> are different
- All elements must have closing tags, or your document is considered malformed/illegal
- Please! Use simple and self describing syntax in you’re XML documents
o Example:
<code>
<message>
<note>Give me a cookie!</note>
</message>
</code>
- XML preserves white space
- Comments are done in the following format <code><!-- Insert comment here --></code>
- All new lines are seen as a line feed so (CR/LF = LF)
- All XML documents should start with a tag similar to
<code><? xml version=”1.0” encoding=”ISO-8859-1”?></code>
- Properly nest your tags
Good: <books><page number=”2”></page></books>
Bad: <books><page number=”2”></books></page>
Sample Document
<? xml version=”1.0” encoding=”ISO-8859-1”?>
<! -- This is the root element -->
<scorecard>
<team>The Cookie Monsters</team>
<score round=”1”>12</score>
</scorecard>
Well, I hope you’ve found some piece of information on here useful, otherwise look at the bright side; it was pretty short and should have made you hungry for a cookie. For more information check w3schools online tutorial, otherwise there is always google.

0 Comments:
Post a Comment
<< Home