Page 1 of 1

not getting all results...

Posted: Sat Dec 30, 2006 10:03 pm
by sarris
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi there.i am having this xml file, [url]http://www.houseonmap.gr/areadata.xml[/url],
and getting the data (X and Y) in this manner

[syntax="javascript"]
for(i=0;i<N;i++){
	tempTerritory = ter_list[i];
	tempid = tempTerritory.getAttribute("id");
	if(tempid==id_wanted){
		X=tempTerritory.getElementsByTagName("t_X")[0].childNodes[0].nodeValue;
		Y=tempTerritory.getElementsByTagName("t_Y")[0].childNodes[0].nodeValue;
		break;
	}
	var area_list = tempTerritory.getElementsByTagName("area");
        for(j=0;j<area_list.length;j++){
		tempArea = area_list[i];
		tempid = tempArea.getAttribute("id");
         	if(tempid==id_wanted){
		        X=tempArea.getElementsByTagName("X")[0].childNodes[0].nodeValue;
		        Y=tempArea.getElementsByTagName("Y")[0].childNodes[0].nodeValue;
		        break;
                }
        }

}
for some reason i am getting only when the wanted id is 1,2,3, 11,22,33 and never for 12,21,23,31,32
If anyone can help it would be great.thanks


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Dec 31, 2006 4:14 am
by Kieran Huggins
where do you set "id_wanted"?

I think we'll need more context (code) to help solve this one.

Posted: Sun Dec 31, 2006 10:53 am
by feyd
Sarris, we've had to edit at least eight of your forty posts to use syntax highlighting. That's a very high percentage. Please start using the syntax highlighting tags.

Posted: Sun Dec 31, 2006 10:54 am
by sarris

Code: Select all

/*AJAX*/
function getHTTPObject() {
	if (typeof XMLHttpRequest != 'undefined') {
		return new XMLHttpRequest();
	}
	try {
		return new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			return new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {} } return false;
}

function makeRequest(id_wanted){

	var url = "http://www.houseonmap.gr/areadata.xml";
	var http_request = getHTTPObject();
        http_request.open("GET", url, true);
        http_request.onreadystatechange = function() {
               if(http_request.readyState == 4) {
                    if(http_request.status == 200){
                           GetData(http_request,id_wanted);

                   }
            }
	}
       http_request.send(null);
}

function GetData(http_request,id_wanted){
map.setZoom(6);
var response  = http_request.responseXML;
	//GET THE ROOT OF THE DATA
	var root = response.documentElement;
	var ter_list = root.getElementsByTagName("Territory");
        var N = ter_list.length;
        var FLAG;    //0 is territory 1 is area...moreover when flag = 1 means area found so break out of the loop of the territories
        var i;
	var j;
	var X;
	var Y;
	var tempTerritory;
	var tempArea;
        var tempid;
for(i=0;i<N;i++){
        if(FLAG == 1) break;
        FLAG = 0;
	tempTerritory = ter_list[i];
	tempid = tempTerritory.getAttribute("id");
	if(tempid==id_wanted){
		X=tempTerritory.getElementsByTagName("t_X")[0].childNodes[0].nodeValue;
		Y=tempTerritory.getElementsByTagName("t_Y")[0].childNodes[0].nodeValue;
                FLAG = 0;
		break;
	}
	var area_list = tempTerritory.getElementsByTagName("area");
        for(j=0;j<area_list.length;j++){
		tempArea = area_list[i];
		tempid = tempArea.getAttribute("id");
         	if(tempid==id_wanted){
		        X=tempArea.getElementsByTagName("X")[0].childNodes[0].nodeValue;
		        Y=tempArea.getElementsByTagName("Y")[0].childNodes[0].nodeValue;
		        FLAG = 1;
                        break;
                }
        }

}
document.form1.Acor.value = i;
document.form1.Bcor.value = j;
document.form1.Ccor.value = area_list.length;
document.form1.Dcor.value = FLAG;
document.form1.Ycor.value = Y;
document.form1.Xcor.value = X;
if(FLAG == 0) {map.setZoom(12);}
if(FLAG == 1) {map.setZoom(14);}
map.panTo(new GLatLng(Y, X));
http_request.abort();
}

Code: Select all

<select size="1" name="Area" onchange = "javascript: makeRequest(this.value)">
	<option value="1" selected>Athens Center</option>
	<option value="12">---Kolwnaki</option>
	<option value="11">---Plaka</option>
	<option value="2">Boreia Proasteia</option>
	<option value="21">---Kifisia</option>
	<option value="22">---Papagou</option>
	<option value="23">---Xalandri</option>
	<option value="3">Notia kai Anatoliki Attiki</option>
	<option value="31">---Vyrwnas</option>
	<option value="32">---Kaisariani</option>
	<option value="33">---Zwgrafos</option>
	</select>
Thats it. Thanks for anything you can do