put into variable javascript

hello, i have this xml file


I need to be able to get the longitude and latitude into a variable using javascript.  I need it for an asp page.  thanks.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

christampaAuthor Commented:
isnt there any xml experts on this site????
Here is a sample page I have put together for you.  It is based on the example from W3schools:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


var xmlHttp;

function alertLatLong()
var url="http://api.local.yahoo.com/MapsService/V1/geocode?appid=yahoo&street=702+First+ave&city=Sunnyvale&state=CA";
xmlHttp.open("GET", url , true);

function stateChanged()
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
var xml = xmlHttp.responseXML
var lat = xml.selectSingleNode("//Latitude").text;
var long = xml.selectSingleNode("//Longitude").text;
alert("Latitude: " + lat + ", Longitude: " + long);

function GetXmlHttpObject(handler)
var objXmlHttp=null;

if (navigator.userAgent.indexOf("Opera")>=0)
alert("This example doesn't work in Opera");
if (navigator.userAgent.indexOf("MSIE")>=0)
var strName="Msxml2.XMLHTTP";
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
objXmlHttp=new ActiveXObject(strName);
return objXmlHttp;
alert("Error. Scripting for ActiveX might be disabled");
if (navigator.userAgent.indexOf("Mozilla")>=0)
objXmlHttp=new XMLHttpRequest();
return objXmlHttp;


<body onload="alertLatLong();">

Gertone (Geert Bormans)Information ArchitectCommented:
Hi christampa,
> isnt there any xml experts on this site????

plenty, but they all have jobs outside Experts Exchange

here is what you need, asuming you have msxml4 installed

                 var oXML = new ActiveXObject("Msxml2.XMLHTTP.4.0");
                 oXML.open("GET", "http://api.local.yahoo.com/MapsService/V1/geocode?appid=yahoo&street=702+First+ave&city=Sunnyvale&state=CA", false);
                 var oRes = oXML.responseXML;
                 var oLat = oRes.selectSingleNode("//*[local-name() = 'Latitude']").text;
                 var oLong = oRes.selectSingleNode("//*[local-name() = 'Longitude']").text;
you can also use the XML server http object, it is just a matter of thread safety

simple get to get the XML object
and two simple selectSingleNode to get the elements you want


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

christampaAuthor Commented:
hahahaha they both worked!!!!!!!!!!!! thank you thank you!!!

how can i give you both 500 points?
Gertone (Geert Bormans)Information ArchitectCommented:
>how can i give you both 500 points?

glad it worked,
you can't give twice 500 pts,
but you can split points if you want (push that button at the bottom)
or give points to mshogren for being first

christampaAuthor Commented:
yours actually worked slightly better because mshogren answer asked me if i wanted to accept it getting information from another web site.  yours didnt.  is there a reason for that?
Gertone (Geert Bormans)Information ArchitectCommented:
Mshogrens code is set up for a browser as AJAX code
- he (apologies if you are not a "he", ms) copied the code for browsers, giving some browser detection code for choosing the correct XML HTTP object
(I did not do that since you asked for ASP code, so I assume you are doing that server side, Windows)
- he set the code up for asynchronous XML retrieval... xmlHttp.open("GET", url , true);
the "true" makes that happen
this means that you do the request, but continue with the rest of your code
if the respons comes in, the readystate changes and the function stateChanged() is launched
I think that this raises the extra request for acceptance (activeX in the browser)
I set that third parameter to false, this means synchronous, so the code waits until the XML comes in
you can do error reporting based on the object having content or not after the request

hope this helps
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.