# Trouble search in XML

**URL:** <https://forum.kirupa.com/t/trouble-search-in-xml/174996>\
**Category:** Uncategorized\
**Created:** [January 10, 2006, 11:12pm UTC](https://forum.kirupa.com/t/trouble-search-in-xml/174996 "2006-01-10T23:12:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eliaN](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@eliaN](https://forum.kirupa.com/u/eliaN)\
**Post date:** [January 10, 2006, 11:12pm UTC](https://forum.kirupa.com/t/trouble-search-in-xml/174996/1 "2006-01-10T23:12:26Z")

</div>

I’m trying to search in more then 1 XML files but I’m doing something wrong! if I indert a value to find - I have to press search 2 times that it finds it?!? the first time it finds “undefined”  
please HELP! what am I doing wrong(look at the attached files)

var found;  
var searchFiles:Array = [“washbasins.xml”, “bathtubs.xml”];  
//  
function searchXML(searchVar) {  
for (var j = 0; j\<searchFiles.length; j++) {  
var s:XML = new XML();  
s.ignoreWhite = true;  
s.load(searchFiles[j]);  
s.onLoad = function() {  
var searchCurrent:Array = this.firstChild.childNodes;  
for (var i = 0; i\<searchCurrent.length; i++) {  
if (searchVar == searchCurrent\*.attributes.item\_txt) {  
found = searchCurrent\*.attributes.item\_txt;  
//trace(searchCurrent\*.attributes.item\_txt);  
//trace(searchCurrent\*.attributes.url);  
break;  
}  
}  
};  
}  
}  
search\_btn.onRelease = function() {  
if (!search\_txt.text) {  
trace(“insert value”);  
} else {  
searchXML(search\_txt.text);

trace(" "+found);  
//here i should check if nothing is found  
}  
};
