Vision Posted March 21, 2011 Posted March 21, 2011 (edited) Hello!, im trying to work abit with googles map api. Hers the standard code #include <File.au3> Global $oXML = ObjCreate("Microsoft.XMLHTTP") $oXML.Open("GET", "http://maps.google.com/maps/api/directions/xml?origin=48143,Muenster&destination=23560,Luebeck&sensor=false", 0) $oXML.Send Global $sFile = "test.xml" FileWrite($sFile, $oXML.responseText) in the test file are the complete xml answer. but i just want / or need one value at the end of the file is the point "distance" / text = (distance in kilometers) (AT LINE 589) so the value i search is "341 km" but the value can change depending on the adress i put in the post. so how i can get only this value from the hole xml answer? or how i can seperate this value? sorry for my bad english Edited March 21, 2011 by Vision
saywell Posted March 21, 2011 Posted March 21, 2011 How about you read the file into an array - _FileReadToArray display it, to make the next steps easier to code: Then find all the occurrences of "<distance>" using _ArrayFindAll Take the LAST of these [using the value returned] and look in the original array for the value of the element 2 entries below it. William
Vision Posted March 21, 2011 Author Posted March 21, 2011 (edited) im getting allways 0 / -1 back #include <File.au3> #include <Array.au3> Global $aRecords Global $aiResult Global $oXML = ObjCreate("Microsoft.XMLHTTP") $oXML.Open("GET", "http://maps.google.com/maps/api/directions/xml?origin=48143,Muenster&destination=23560,Luebeck&sensor=false", 0) $oXML.Send Global $sFile = "test.xml" FileWrite($sFile, $oXML.responseText) _FileReadToArray("test.xml",$filetoarray) $result = _ArrayFindAll($filetoarray, "<text>") Msgbox(0,'Results:', $result) MsgBox(0,"Error", @error) the array in $filetoarray is ok but arrayfindall doesnt work?! Edited March 21, 2011 by Vision
saywell Posted March 21, 2011 Posted March 21, 2011 OK, that gave an error that $filetoarray isn't an array, which I don't understand. But I've found another way: #include <File.au3> #include <Array.au3> Global $aRecords Global $aiResult, $filetoarray, $handle, $XML, $newtext Global $oXML = ObjCreate("Microsoft.XMLHTTP") $oXML.Open("GET", "http://maps.google.com/maps/api/directions/xml?origin=48143,Muenster&destination=23560,Luebeck&sensor=false", 0) $oXML.Send $XML = $oXML.responseText $array = StringSplit ($XML,"</distance>",1) ; splits at every instance of /distance $array2 = stringsplit ($array[$array[0]-1], "<text>", 1) ; selects the last split segment, which contains the total distance, and splits it down by text occurrences ;_ArrayDisplay ($array2) ; just to demo $Distance = StringTrimRight($array2[$array2[0]],11) ; picks last instance and trims the end tags. Msgbox(0,'Results:', $distance) thia works on the example you gave, but you'd have to test i for reliability with other values etc. William
JohnOne Posted March 21, 2011 Posted March 21, 2011 I'm no xml expert, infact I've never even used it/them. But I have seen an xml dom wrapper in example scripts, and I think xml is similar to html but has nodes and suchlike. I'm probably talking gibberish but I'll bet there is a function in that UDF for exactly what you want. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now