for some reason, i can’t seem to get the node values i need from this simple xml… it’s mindboggling! I’m sure i’m overlooking something b/c i’ve been screwing around with this too long.
I originally started doing it the way i usually do by creating vars to store nodes and referencing the vars to call child nodes. that seemed to give me an array structure at that point and I could no longer reference any nodeValues.
what i have should work though, but i’m getting null and undefined.
here’s code:
getIPLocation=function(ip){
retXML=new XML();
retXML.ignoreWhite=true;
retXML.onLoad=function(){
trace("XML: "+this);
trace("status: "+this.status);
info=this.firstChild.firstChild.nextSibling.nextSibling.nextSibling.firstChild;
trace("info: "+info);
_global.userLoc=new Object();
userLoc.cityState= info.firstChild.firstChild.nodeValue;
userLoc.countryName= info.firstChild.firstChild.nextSibling.nodeValue;
userLoc.countryAbbrv=info.firstChild.firstChild.nextSibling.nextSibling.nodeValue;
var Coords:String= info.firstChild.firstChild.nextSibling.nextSibling.nextSibling.firstChild.firstChild.nodeValue;
trace("coords string: "+Coords);
trace("city/state: "+userLoc.cityState);
trace("country name: "+userLoc.countryName);
trace("country abbrev: "+userLoc.countryAbbrev);
trace("location coords: "+userLoc.latLong);
};
retXML.load("http://api.hostip.info/?ip="+ip);
here’s the xml:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<HostipLookupResultSet version="1.0.0" xmlns="http://www.hostip.info/api" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hostip.info/api/hostip-1.0.0.xsd">
<gml:description>This is the Hostip Lookup Service</gml:description>
<gml:name>hostip</gml:name>
<gml:boundedBy>
<gml:Null>inapplicable</gml:Null>
</gml:boundedBy>
<gml:featureMember>
<Hostip>
<gml:name>Grandville, MI</gml:name>
<countryName>UNITED STATES</countryName>
<countryAbbrev>US</countryAbbrev>
<!-- Co-ordinates are available as lng,lat -->
<ipLocation>
<gml:PointProperty>
<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:coordinates>-85.7561,42.9038</gml:coordinates>
</gml:Point>
</gml:PointProperty>
</ipLocation>
</Hostip>
</gml:featureMember>
</HostipLookupResultSet>
I should definitely mention that this works:
userLoc.cityState=info.firstChild.firstChild.nodeValue;
while the others do not!