Download the files here.
TUTORIAL CONTENTS
  • Introduction
  • Flash/XML Syntax
  • Accessing nodes
  • Digging deeper
  • Power of Attributes
  • HTML and Text in XML
  • Making a Search Engine
  • Preloading XML files
  • XML/FLASH SITES AND TUTORIALS
  • Tupps web site
  • Flash 5 and XML
  • XML Table Constructor Kit
  • Using an XML file to load Chart components
  • Macromedia XML tutorial
  • Integrating XML and Flash in a Web Application
  • AUTHOR´s XML TUTORIALS/FILES
  • XML searchable database I
  • URLs and Asfunctions (II)
  • XML searchable database III
  • XML database Component
  • XML slideshow Component
  • XML scroller menu Component
  • Flash - XML Tutorial

    HTML and Text in XML

    You have probably learnt how to use HTML in regular textfiles, which are loaded and parsed using loadVars. From what I have seen so far many people seem to have problems adding HTML to XML. There are some very complex solutions offered, but actually it is much simpler. I don´t know it was known so far but I found a way, which is very simple to add HTML to XML textnodes. Before I continue explaining have a look at a little XML file, which has tons of HTML in it. Click on the bold name and a web site will open.

    Now let´s have a look at the XML file.

                                      <?xml version="1.0"?>
                                      <models>
    	                                   <susan>
                                      <p>
                                      <b><a href="susan.html" target="_blank"><u>Susan Black</u></a></b>
                                      <li>age: 21</li>
                                      <li>eye color: dark blue</li>
                                      <li>hair color: black</li>
                                      <li>foreign language: german</li>
                                      </p>
    	                                    </susan>
                                      </models>
    

    Surprisingly, we have more childnodes like <p> or <b> and even links. Before we look at the parsing look how browsers will show this file. It is just like any other XML file. Now we can look what we need to code to parse this in Flash. We would think that we need a very complex actionscript to parse this XML file.

                                      function listItems(model01){
                                           mainField.htmlText=model01.firstChild;  //do not use .nodeValue her
                                      }
    

    That is all, basically one line, no gimmicks or whatever. How come? First of all the Flashplayer unlike the browsers can distinguish between pure XML and HTML tags. HTML tags are recognized as such, which makes our life really easy. However, to get it parsed correctly I found it is important to flank the textnode with the HTML tag <p> and its closing tag <p>. This somehow tells the Flashplayer that this should be treated like a textfile as in loadVars. Ommitting the tags will stop parsing the XML file after one of the HTML tags. Try it out. The next important part is that in our actionscript we ommit the extension .nodeValue so that the Flashplayer recognizes this a child of type 1 rather than a textnode of type 3.

    Links

    I would like to add some comments to links. If you use target in the link put the contents in quotations after the comma. The XML file as shown above will be parsed by the browser as you have seen. When you add very complex links with unusual characters, the Flashplayer will also parse the link correctly. However, the browsers will not any more recognize such file as a parsable XML file and will give a fault notice.


    PREVIOUS          NEXT