5 Killer Tips To Get You Started on XML
July 3rd in Article, Coding, Coding, ScarletBits, XML by h1brd .

5 Killer Tips To Get You Started on XML

XML, you heard about it, you even use it on a daily basis, but do you actually know what it is?

On this post we bring you 5 killer tips to get you started on xml coding, either to understand it better or to actually get the bases to start creating your own xml valid documents.


h1brd

Marco Sousa is a Web Designer & Front End Developer. He is a Co-Founder of Scarletbits.com. Follow him on Twitter for more updates!

VIsit h1brd's website

XML, you heard about it, you even use it on a daily basis, but do you actually know what it is?

On this post we bring you 5 killer tips to get you started on xml coding, either to understand it better or to actually get the bases to start creating your own xml valid documents.

1. Learn what XML actually means.

And for that we can pickup the definition from Wikipedia that states:

XML (Extensible Markup Language) is a general-purpose specification for creating custom markup languages. It is classified as an extensible language, because it allows the user to define the mark-up elements.”

source: http://en.wikipedia.org/wiki/XML

You should also take some time to go through the official W3C documentation for XML that you can find here: http://www.w3.org/XML/ . Although the documentation is vast, you can get a good learning from those pages, especially if you are interested in web standards.

2. Understand a XML document structure.

XML documents are all about creating a logic structure for your data.
The author chooses the tags and uses them in the best way to organize the type of content in a hierarchy, like in this example:




Scarketbits.com
h1brd
XML Documents
Showing an example of a XML Document!


You can get an idea of this XML document hierarchy in the next illustration:

xml 5 Killer Tips To Get You Started on XML

3. Learn the Rules to create a valid XML document.

In order for your XML document to be valid, there are some rules you need to follow:

  • A XML document needs to start with its declaration:


    or

  • A XML document needs to have one or more elements

    the first one that contains all the rest of the document is called the root element.

  • Close All Tags…

    the only exception to this rule are empty elements that can have a single tag that ends with “/>

  • …In the correct Order!

    you need to close tags in the right order, if you have two open tags to close, the first one you opened needs to be closed last.

  • Attribute values need to be contained inside ” “

    if the attribute itself uses ” “, you can then contain it with ‘ ‘

4. Learn how to use Attributes.

In XML attributes can be optional or requested and provide additional information about elements.
The best way to understand this is to see an example which in this case I will grab from W3Schools:

Attributes often provide information that is not a part of the data. In the example below, the file type is irrelevant to the data, but important to the software that wants to manipulate the element:

computer.gif

There are no limits to the amount of attributes an element can have.

5. Understand Namespaces.

In XML the developer is free to create the document at his/her own taste and this often causes conflicts when documents from different XML applications and developers come together. To solve this we use prefixes.

To use a certain prefix, a correspondent namespace needs to be declared first.
To declare the namespace we use the attribute xmlns:

xmlns:h1brd="http://scarletbits.com/h1brd"

Its value needs to be a URI : Uniform Ressource Identifier.
This attribute is not a physical address of a resource.

The prefix h1brd starts to qualify the elements:


Marco Sousa

Usefull Links:


2 Comments

  • h1brd
    July 3, 2009
  • Carlos
    July 3, 2009

Leave A Comment.