You are viewing a post from electro kami classic - hello!

XML: Basic Structure

xml tutorial basic structure

XML can be used for a lot of different web technologies, from AJAX, JavaScript, PHP, and Flash, to JSP, ASP, Java, Ruby, and Perl. Basically, if you want to be a web developer or designer, you need to get a basic understanding of XML (although you could certainly get by without ever needing it).

XML sounds like it can be used everywhere … but what is XML for?

In a nutshell, XML is used as an format engine to easily transmit data between many different types of programming languages.

XML structure makes encourages simplicity and usability with strong Unicode support (to use the myriad languages of the world). XML is created for documents, but it is extended into arbitrary data structures, file centric database organization, and even web services.

Before we get ahead of ourselves, let’s start with a look at a basic XML file.

XML file structure

[xml]
<? xml version="1.0" encoding="UTF-8" ?>
<animal type="dogs">
<type>
<name>Labrador</name>
<appearance fur="short" size="large">playful</appearance>
</type>
<type>
<name>Bulldog</name>
<appearance fur="short" size="medium">mean</appearance>
</type>
<type>
<name>Golden Retriever</name>
<appearance fur="medium" size="large">fluffy</appearance>
</type>
<type>
<name>Dachshund</name>
<appearance fur="short" size="small">long</appearance>
</type>
</animal>
<!– this is a comment, you have reached the end of the file –>
<!– comments are also helpful if XML elements control items –>
<!– like settings in a Flash file or JavaScript function –>
[/xml]

There are four elements in our example XML file: animal, type, name, and appearance.

The name and appearance elements are children of type, which is a child of the root element animal.

Appearance has two attributes, fur and size.

Using this standardized structure, programmers and programs alike can now access the data within this file and parse it into meaningful objects or items like arrays, image galleries, Flash layouts, dynamic content, or just about anything else that can take in arbitrary data.

The point is, XML makes your data portable and usable in many different web and desktop programming languages.