Script: XML-text

Text from an attribute

//Loading the xml file, myText is an instance name holding the file
myText = new XML();
myText.load("xml_text1.xml");
//newText is function where we access the xml tree
myText.onLoad = newText;
//we test if loaded
if (this.loaded) {
    InstanceName_0.text = "Text loaded."
}else{
    InstanceName_0.text = "Text not found."
}
//accessing the tree
function newText() {
    //looping through the tree
    for (var count01=0; count01<=myText.childNodes.length; count01++) {
        //text is the name of root node
        if (this.childNodes[count01].nodeName.toLowerCase() == "text") {
            //textDescryption contains all nodes
            textDescryption = this.childNodes[count01];
            //here we access the attribute myText containing the text file
            InstanceName_0.text = textDescryption.attributes.myText;					
        }
    }
}

Text from a node

//see description in the file1
myText = new XML();
myText.load("xml_text2.xml");
myText.onLoad = newText;
if (this.loaded) {
    InstanceName_0.text = "Text loaded."
}else{
    InstanceName_0.text = "Text not yet loaded."
}
function newText() {
    for (var count01=0; count01<=myText.childNodes.length; count01++) {
        if (this.childNodes[count01].nodeName.toLowerCase() == "text") {
            textDescryption = this.childNodes[count01];
            //here we access the firstchild of "text" which contains our text
            //careful when making the xml file, check white space
            //nodes with myxml.ignoreWhite=true;
            InstanceName_0.text = textDescryption.firstChild.nodeValue;
        }
    }	
}