when sending xml data. //This routine will remove CR/LF pairs and replace them with a space procedure ConvertCRLFtoSpace; begin if plainData.Count > 1 then begin // break trailing CR&LF plainData.Text := StringReplace(Trim(plainData.Text), sLineBreak, ' ',[rfReplaceAll]); end else begin plainData.Text := Trim(plainData.Text); end; end;begin result:=false; //by default, we get failure response in error plainData := TStringList.Create; //init the container for xmiting the xml try plainData.Text:=getXML; //get the xml from the class and put it in the container Http:=TidHTTP.Create(nil); //create the http class try HTTP.readTimeout := 10000; //setup the http timeouts and xmit types HTTP.ConnectTimeout := 10000; HTTP.Request.Contenttype := 'text/xml'; HTTP.HTTPOptions := []; if enableLogging then //if we are going to log the events (useful if there's a problem) begin logFile := TLogFile.Create(nil); //create the log file logFile.FileName:=logFileName; //set the default log file name - NOTE: you could get fancy with this, but I normally don't use it logFile.Active:=true; //activate the log file (creates the file and intializes everything) HTTP.Intercept := logFile; //set the logFile to the intercept of the HTTP to capture the events end; response:=TStringList.Create; //create the response container try ConvertCRLFtoSpace; //make sure you strip cr/lf pairs out or the xml will be malformed response.Text := HTTP.Post(URL, plainData); //post the xml and receive the response xml result:=true; parseResponse(response); finally response.Free; end; finally Http.free; //free the http class end; finally plainData.Free; //free the container class end;end;{ TMapQuestGeoCoder }procedure TMapQuestGeoCoder.ClearReturnedAddys;var ix:integer;beginfor ix := 0 to fReturnedAddresses.Count-1 do fReturnedAddresses.Address[ix].Free;fReturnedAddresses.Clear;end;constructor TMapQuestGeoCoder.Create;beginfURL:='http://geocode.free.mapquest.com/mq/mqserver.dll?e=5&'; //this is the free server address. if you sign up for a different type of account, you'll want to set this to your account typefReturnedAddresses:=TReturnedAddyList.Create;end;destructor TMapQuestGeoCoder.Done;beginClearReturnedAddys;fReturnedAddresses.Free;end;function TMapQuestGeoCoder.getXML: string; //returns the xml formated per the MapQuest APIconst geocodeXML = '<?xml version="1.0" encoding="ISO-8859-1"?>'+ '<Geocode version="1">'+ '<Address>'+ '<AdminArea1>%s</AdminArea1>'+ '<AdminArea3>%s</AdminArea3>'+ '<AdminArea5>%s</AdminArea5>'+ '<PostalCode>%s</PostalCode>'+ '<Street>%s</Street>'+ '</Address>'+ '<GeocodeOptionsCollection Count="0"/>'+ '<Authentication Version="2">'+ '<Password>%s</Password>'+ '<ClientId>%s</ClientId>'+ '</Authentication>'+ '</Geocode>';beginresult := Format(geocodeXML, [Country,State,City,PostalCode,Address,Password,ClientID]); //make the request xml for geocding an addressend;procedure TMapQuestGeoCoder.parseResponse(response: TStringList);var DOC:TXMLtoDomParser; DOM:TDOMImplementation; XML:TDOMDocument; LocCollection:TDomNodeList; Geo, Node:TDomNode; //you can't trust that the xml contains ALL element names so this wraps the testing conditions up //to safely get the node values or a blank when not in the xml function SafeGetNodeValue(node:TDomNode; name:string):string; var DomElement:TDomElement; begin result:=''; DomElement:=Node.GetFirstChildElement(name); if DomElement=nil then exit; if DomElement.ChildNodes=nil then exit; if DomElement.ChildNodes.Length=0 then exit; result:=DomElement.ChildNodes.Item(0).NodeValue; end; //same as the previous but designed to get a subelement (LatLng/Lat or LatLng/Lng) function SafeGetSubNodeValue(node:TDomNode; rootName, subName:string):string; var RootElement, SubElement:TDomElement; begin result:=''; RootElement:=Node.GetFirstChildElement(rootName); if RootElement=nil then exit; SubElement:=RootElement.GetFirstChildElement(subName); if subElement=nil then exit; if subElement.ChildNodes=nil then exit; if subElement.ChildNodes.Length=0 then exit; result:=subElement.ChildNodes.Item(0).NodeValue; end;begin ClearReturnedAddys; //make sure there are no saved addys DOC:=TXMLtoDomParser.Create(nil); //create the xml parser DOM:=TDOMImplementation.Create(nil); //create the dom try DOC.DOMImpl:=DOM; //assign the dom to the xml parser XML := DOC.StringtoDom(response.Text,'mapquest.xml',nil,true); //convert the response text to and xml document. NOTE: 'mapquest.xml' forces the correct creation of the node structures. If you pass blank, you get NO NODES try LocCollection := XML.GetElementsByTagName('LocationCollection'); //get the location collection (group of geoaddresses 1..n) if LocCollection=nil then exit; Node:=LocCollection.Item(0); //get the top level node Geo:=Node.GetFirstChildElement('GeoAddress'); //get the first GeoAddress while Geo<>nil do //while we have a GeoAddress begin fReturnedAddresses.Add(TReturnedAddy.Create(SafeGetNodeValue(Geo, 'Street'), //addy SafeGetNodeValue(Geo, 'AdminArea5'), //city SafeGetNodeValue(Geo, 'AdminArea3'), //state SafeGetNodeValue(Geo, 'PostalCode'), //zip