Reputation: 535
I'm trying to use Google Maps to calculate the distance between 2 points.I have the following url :
http://maps.google.com/maps/api/directions/xml?language=fr&origin="+parm1+"&destination="+parm2+"&sensor=false
I'm quite a newbie in managing xml with x++ so how can I get the xml code returned by my url and parse it to extract the data I need (distance node values).
Upvotes: 1
Views: 1516
Reputation: 11544
I was playing around with the two links Jan posted and got something you should be able to work with. I noticed some strangeness with the "node.hasChildNodes()", where it would say there was a child, when there was none, but it had available text. See if you can work with this.
static void XML_WebService_CodeGoogle(Args _args)
{
System.Net.WebClient webClient = new System.Net.WebClient();
str google = "http://maps.google.com/maps/api/directions/xml?language=en&origin=85251&destination=46220&sensor=false";
str retVal = webClient.DownloadString(google);
XMLDocument doc=XMLDocument::newXml(retVal);
XmlNamedNodemap attributes;
XmlElement root = doc.root();
XmlNode node = root.firstChild();
str numOfSpaces(int _depth)
{
str spc;
int n;
;
for (n=0; n<=_depth; n++)
spc+=' ';
return spc;
}
void dig(XmlNode _node, int _depth = 0)
{
XmlNode sib;
;
if (_node == null)
return;
if (_node.hasChildNodes())
info(strfmt("%1%2", numOfSpaces(_depth), _node.name()));
if (_node.hasChildNodes())
dig(_node.firstChild(), (_depth+1));
else
info(strfmt("%1[%2]", numOfSpaces(_depth), _node.innerText()));
sib = _node.nextSibling();
if (sib)
dig(sib);
}
;
dig(node);
}
Upvotes: 0
Reputation: 18051
First, see this answer.
Then have a look here:
http://www.axaptapedia.com/Webservice
http://www.axaptapedia.com/XML
How you do it may in part depend on you AX version.
Upvotes: 1