Quantunet.com

My Account

Joins Us
Flash 8 Actionscript 2.0 Knowledgebase
XML Knowledgebase  

What is XML ?
"XML" stands for extensible mark up language. It is a way of structuring, arranging and representing data. in a way that is both universally readable and easy to use. One of the challenges in creating a highly uasable code for structuring data files has been the need to create a code that can be efficiently parsed and yet easily read by humans.

Why Use XML?
XML is rapidly becoming the standard for transfering and managing data on the web. It is compatable on various platforms and a multitude of devices.

Introduction To eXtensible Markup Language
xml is pure text

main goal of xml is to seperate content of information form the presentation of the infomration.

xml carefully desacribes pieces of data and the relashonship betweeen them.

adds meaning to data to produce usefull information that can be used in intelligent search engines.

xml establishes a strict set of rules that any markup language such as VRML CML MAthML must follow.

Questions

What does parse mean?

When code is parsed it is read and correctly interpreted by a computer.

How are tags in XML different from tags HTML ?
XML looks very similar to HTML in appearence. html tags are primariily used to contain information about formatting. tags in xml are used to contain and clasify data.

The XML Code
Elements (Non emepty)

The syntax for an element is:

<name>content</name>


Empty elements

<name/>


Attributes

<name attribute="value">content</name>


Nesting Elements (basic)
tree based data structure

<book>
       <title>Romeo And Juliete</title>
       <author>William Shakespere</author>
       <date>1597</date>
</book>

<book>
        <title>The Catcher In The Rye</title>
        <author>Jerome David Salinger</author>
        <date>1951</date>
</book>


Root elements

 

<library>
<book>
       <title>Romeo And Juliete</title>
       <author>William Shakespere</author>
       <date>1597</date>
</book>

<book>
        <title>The Catcher In The Rye</title>
        <author>Jerome David Salinger</author>
        <date>1951</date>
</book>
</library>



Basic XML Coding Rules for Validation

  1. All elements must have alphanumerically identicle opening and closing tags (unless empty elements)
  2. Elements names are case sensitve (case sensitive).
  3. Nested tags should be closed before outer tags
  4. All attribute values must appear within quotation marks.
  5. Every XML document must have a root element.

For XML to be considered "Valid" code it must udergo a process of validation which checks the syntax of the XML code to make sure that it will parse correctly.

Tags
singleton tags

1.All elements must have alphanumerically identicle opening and closing tags (unless empty elements)

 



2.Elements names are case sensitve.
Unlike other mark up languages in xml tag names are case sensitive. This meanse that the parser sees the tags "myelement name" and "myElementName" as two distinctly different tags making the code below wrong (as opening and closing tags are no identicle).

<myelementname>Contents of my element</myElementName>



3. Nested tags should be closed before out tags:
Unlike HTML in XML the order in which you close nested tags is important. For example in HTML this is common practice:

<font face = "Ariel"><color ="#FF0000"> Hello my name is Bob</font></color>

The HTML an still be parsed by web browsers with XML this is not the case. One of the important differences between HTML and XML is that XML has a far stricter set of rules the must be met if the code is to be parsed. This strictness is partly in response to the problems developers faced when producing web content as html left too much toom for interpretation forcing web browsers to guess how a web page should be presented.

In XML nested tags must be closed before outer tags in order of heirachy.

<outer tag>
        <innner tag>
        The contents of the inner tag.
        </innner tag>
</outer tag>

4.All attribute values must appear within quotation marks.

 



5.Every XML document must have a root element.

<root_name>

       <outer>
               <innner>
               The contents of the inner tag.
               </innner>
       </outer>

       <outer>
               <innner>
               The contents of the inner tag.
               </innner>
       </outer>

</root_name>


Comments
Adding comments in your XML document can be a tremendous help to anyone trying to resue or develope your xml code. A with other mark languages and programming languages comments serve no function in the code other than to explain section of code or add remarks about the xml document as a whole. It is therfor important that comments be ignored when the XML document is parsed. To do this just as with other text in your XML document comments must follow a specific syntax that make them stand appart form the xml code itself.

To create a comment in an XML document

<!-- This is a comment. -->

Basic Comment Rules

  1. Comments are not valid when they are placed within a tag.
  2. Comments must not contain two hiphens in a row accept at the begining and the end of a comment

<!-- Using comments helps users add notes or explanations to code-->

<root_name>
       <!-- This the opening tag of the element innner-->
       <outer>
               <innner>

               The contents of the element inner.
               </innner>
       </outer>

       <outer>
               <innner>
               The contents of the element inner.
               </innner>
       </outer>

</root_name>


Constructing An XML Document

Selecting a XML editor
Notepad, Wordpad Dreamweaver, free graphical editors

XML In Dreamweaver

[How to create a new XML document in flash]
[How to build a simple Cascading Style Sheet for an XML file]
[Viewing a CSS formatted XML file in Dreamweaver]
[Creating A Basic RSS Feed]

 

<?xml-stylesheet type="text/css" href="myStyleSheet.css"?>

 

XML Declaration
The first thing that should apprear at the beginnig of your XML document is an XML declaration. A declaration tells the parser which version of the XML language is used your document. This allows the parser to select the correct process for validating your XML code.

To create a declaration type " <? " then the XML version you are using to code your document then " ?> ".
For example:

<? xml version = "1.1"?>

Presently the most recent version XML is 1.1

<? xml version = "1.1" encoding="UTF-8"?>


Sample XML Document I

<?xml version="1.0" encode="UTF-8"?>

<library>

        <book>
                <title>Romeo And Juliete</title>
                <author>William Shakespere</author>
                <date>1597</date>
        </book>

        <book>
                <title>The Catcher In The Rye</title>
                <author>Jerome David Salinger</author>
                <date>1951</date>
        </book>

        <book>
                <title>Misery</title>
                <author>Stephen King</author>
                <date>1987</date>
        </book>

</library>



Sample XML Document II (ignore white space)

<?xml version="1.0" encode="UTF-8"?>


<library>

        <book>
                <title>Romeo And Juliete</title>
                <author>William Shakespere</author>
                <date>1597</date>
        </book>

        <book>
                <title>The Catcher In The Rye</title>
                <author>Jerome David Salinger</author>
                <date>1951</date>
        </book>

        <book>
                <title>Misery</title>
                <author>Stephen King</author>
                <date>1987</date>
        </book>

</library>



Creating Well Fomed XML Documents
The difference between valid XML and well fomed XML
An XML document that contains Valid code.....

Advanced XML Structures In Flash

Loading external xml data is a relatively easy task to acomplish task in flash as it will automatically parse the xml code as it loads. However Flash uses a nonvalidating parser so it does not make sure the xml document strictly aheres to any specific standrard xml structure. This means that flash can be quite forgiving if the code does not comply with document type definition (DTD) that it was designed for.

This can be a mixed blessing. In many ways it can be helpfull as it makes flash extremely versatile by default however if you are creating an xml file that must follow specific structure laid out by a DTD flash isn't very usefull at validating the file. Thats why is it importnat to get into good habbits when structuring xml files for flash if you intend to use those files for other applications as flash will not be looking over you shoulder making sure the structure is standards compliant unless you specifically ask it to and include a DTD tag.

Using Internal DTD Tags
In order to agrees on xml structures developers usually put an internal DTD (document type definition) in the xml file. This can be used to put further requirements on the structure of your xml code that is parsed in flash or clarify the xml structure. The DTD is usually put immediately after the xml version declaration for example:

<?xml version="1.0" encode="UTF-8"?>

<!DOCTYPE library[
<!ELEMENT library(book)>
<!ELEMENT book name (author, title, date)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT date (#PCDATA)>
]>

In this example the "!DOCTYPE" "library" sets the name of the rootnode for the xml document. Then the first "!ELEMENT" tag defines "book" as a child node nested in "library". The second "!ELEMENT" tag then defines "author", "title" and "date" as being three child nodes nested in the node "book". The following "ELEMENT" tags defines the data type associated with the nodes author, title and date as "#PCDATA" which stands for "parsed character data". This tells any parser that there is important data in the nodes "author", "title" and "date" that must be read.

The xml data along with the expected tags in the expected structure follows the DTD information.

<?xml version="1.0" encode="UTF-8"?>

<!DOCTYPE library[
<!ELEMENT library(book)>
<!ELEMENT book name (author, title, date)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT date (#PCDATA)>
]>


<library>

        <book>
                <title>Romeo And Juliete</title>
                <author>William Shakespere</author>
                <date>1597</date>
        </book>

        <book>
                <title>The Catcher In The Rye</title>
                <author>Jerome David Salinger</author>
                <date>1951</date>
        </book>

        <book>
                <title>Misery</title>
                <author>Stephen King</author>
                <date>1987</date>
        </book>

</library>

The three books in this library would be still parsed by flash even if the structure in which they were written in the xml file did not match the DTD as flash has a non validating parser. The advantage of using DTD's in this way is mainly for use outside flash or to maintain standards when working with other developers or other platforms.

Summary: Benifits of using XML to code and structure your data

  • Easy to Use
    It is well suited to organize and structure large amounts of data in a readasble and easy to used cross platform compatible method. XML was developed with a clear goal of standardizaton in mind making it the method of chioce for application or web developers who want to build a data structure that is compatible wth multiple operating sytems on multiple devices.
  • Cross compatability
    XML can be used on devices ranging from LCD photo frames, cell phones, desktop applications and online data management systems it can even be used to create RSS feeds or widgets.
  • Acessibility
    Due to this high level of standardization applications have been developed that can take advantage of XML's acessibility. Because all content in an XML document is declared and labeled (self documented) content can be created that can be restyled or formatted in ways that devlopers never imagined.

  • Customization
    Authors can define thier own tags and are no longer limited to a specific set as in HTML. Easily tailored to be viewable in various formats. Dont have to create two duments. Instead we can create different rules for how the data is displayed.
  • Data Structure
    XML seperates structural information form display information. This allows applications to independently define the semantics (meaning) of the data structures contained in an XML file. This allows XML to be very streamlined and conscience rather than have to include a library of terms used to classify data in the extensible markup language.
  • Load Distribution
    Because only the data must be hosted on a server.Processing perfromed by the server with information about how the data should appear and the methods used to create visual effects can be transfered to the users computer making pages download faster (as only the data needs to download) and websites run faster (as less server processing is needed).
  • Well Formedness
    Generally XML parsers use strict validation and will not parse code that is incorrectly structured or inconsistently formed. This encourages developers to create well formed code without imposing a cumbersome standards on structure as developers can include validation standards to accompany the XML file called a DTD.

Using XML In Flash knowledegbase

[Flash XML actionscript knowledgebase]
[Basic Loading Of A XML File Into Flash Actionscript]
[Loading XML data into an array in Flash]
[Loading data into an array (then convert it to an xml object) in Flash]
[Creating a simple XML preloader]
[Creating An Advanced XML Preloader]



© 2008 Quantunet LLC All Rights Reserved | Intellectual Property | Terms of Use | Privacy
Home | About Quantunet | FAQ's | Contact Us