# Reading XML using AS3 problem

**URL:** <https://forum.kirupa.com/t/reading-xml-using-as3-problem/283848>\
**Category:** flash\
**Created:** [March 11, 2009, 7:37pm UTC](https://forum.kirupa.com/t/reading-xml-using-as3-problem/283848 "2009-03-11T19:37:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beaulne](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/beaulne/32/3027_2.png) [@Beaulne](https://forum.kirupa.com/u/Beaulne)\
**Post date:** [March 11, 2009, 7:37pm UTC](https://forum.kirupa.com/t/reading-xml-using-as3-problem/283848/1 "2009-03-11T19:37:43Z")

</div>

Hello,

I have a problem with my video. On the Stage I have an input box (book\_box) with a “submit” (submit\_btn) button.  
The purpose is to read an xml file for a phrase (the input box) and then output the phrase when found.

The problem is it only ever reads the 2nd item in the XML list… So In this case, test.

The XML

> \<root\>  
> \<books\>  
> \<book\>  
> \<title\>Learning\</title\>  
> \</book\>  
> \<book\>  
> \<title\>test\</title\>  
> \</book\>  
> \<book\>  
> \<title\>ActionScript\</title\>  
> \</book\>  
> \</books\>  
> \</root\>

The AS3

> stop();

//Define The Key word that is in the input box on load.  
book\_box.book\_txt.text=“Book Title”;

//Setup the submit button as a button and its event listener  
submit\_btn.buttonMode=true;  
submit\_btn.addEventListener(MouseEvent.CLICK, submit);

//the buttons function handler  
function submit(e:Event) {  
//Loads the XML  
var xmlLoader:URLLoader = new URLLoader();  
xmlLoader.addEventListener(Event.COMPLETE, onComplete);  
xmlLoader.load(new URLRequest(“store.xml”));

```
function onComplete(evt:Event):void {

    var xmlData:XML=new XML(evt.target.data);

    var bookTitles:XMLList=xmlData.books.book;

    // loop that scans the XML file
    for (var n = 0; n&lt;= xmlData.books.length(); n++) {
        if (bookTitles[n].title==book_box.book_txt.text) {
            trace(bookTitles[n].title);
        } else {
            trace("no Book");
        }

    }
}

```

}
