| home / experts / xml / column82 |
|
After we discovered how the Actionscript deals with different sorts of XML, we now focus on how an XML document is made available in Flash.
If you're experienced with the W3C Document Object Model, you'll feel familiar
with the Flash XML API. Some DOM interfaces are not implemented in the Flash
API or do not comply with the
DOM ECMAScript Language Binding
definition.
There is only one type of object to access XML documents and document fragments: XML.
It has methods and properties mostly from the W3C DOM Node interface but also
from the Document interface (createElement() and createTextNode()).
| Node.nodeType (W3C) | XML.nodeType | XML.nodeName | XML.nodeValue | XML.attributes |
| ELEMENT_NODE | 1 | tag name | null |
|
| TEXT_NODE | 3 |
|
content of the text node | null |
Both the W3C Document Interface
and the Element Interface
define a method getElementsByTagname(). It has one argument in the method signature
and returns an object of type NodeList.
Our Method is invoked with 3 arguments:
null this array is created inside the method.and returns an array of XML objects. Let's look at the code:
function getElementsByTagName(xmlDoc, tagname, xmlObjArray){
var Nodes = null;
if(xmlObjArray == null){
Nodes = new Array();
}else{
Nodes = xmlObjArray;
}
if(xmlDoc.hasChildNodes()){
for(var i=0; i < xmlDoc.childNodes.length; i++){
if(xmlDoc.childNodes[i].nodeName == tagname){
Nodes.push(xmlDoc.childNodes[i]);
}
getElementsByTagName(xmlDoc.childNodes[i], tagname, Nodes);
}
}
return Nodes;
}
First we assign the XML objects to a new array. Then we push all child elements of
xmlDocwith the name in question onto the array.
If you want to avoid pop-ups like this:

you should declare the counter i in for(var i=0; i < xmlDoc.childNodes.length; i++)
with the var "action".
The var argument is required when you invoke
the function recursivly from inside the for block.
Creating the RSS movie...
Produced by Michael Claßen
URL: http://www.webreference.com/xml/column82/3.html
Created: May 26, 2003
Revised: May 26, 2003