Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

css to coldfusion

Status
Not open for further replies.

daNewfie

Programmer
Joined
Oct 14, 2004
Messages
258
Location
CA
Im sending an http request and get an xml file returned.

Code:
<?xml version="1.0" encoding="UTF-8" ?> 
- <kml xmlns="[URL unfurl="true"]http://earth.google.com/kml/2.0">[/URL]
- <Response>
  <name>101 My Street, Toronto, Canada</name> 
- <Status>
  <code>200</code> 
  <request>geocode</request> 
  </Status>
- <Placemark>
  <address>101 My Street, Toronto, Canada</address> 
- <AddressDetails xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
- <Country>
  <CountryNameCode>CA</CountryNameCode> 
- <AdministrativeArea>
  <AdministrativeAreaName>ON</AdministrativeAreaName> 
- <Locality>
  <LocalityName>Toronto</LocalityName> 
- <Thoroughfare>
  <ThoroughfareName>101 My Street</ThoroughfareName> 
  </Thoroughfare>
  </Locality>
  </AdministrativeArea>
  </Country>
  </AddressDetails>
- <Point>
  <coordinates>-82.265905,43.959700,0</coordinates> 
  </Point>
  </Placemark>
  </Response>
  </kml>


now the only information I need there is

<b><coordinates>-82.265905,43.959700,0</coordinates> </b>

the first # is longitude (-82.265905)
the last # is latitude (43.959700)

I want to extract just this data from the xml file and write it to my database...


Regards
Craig
 
opps sorry bout title should be XML to coldfusion
 
Assuming you receive your data as a text string and store it in a variable called XMLTEXT:

Code:
<cfset xml=xmlparse(xmltext)>
<cfset myvalue=xml.kml.response.placemark.point.coordinates.xmltext>
<cfoutput>#myvalue#</cfoutput>

This is one quick and dirty way to do it, but it is tied to the exact block you posted. You can then split the string on the commas using list functions or do whatever you need to do with it..
 
ok...that worked and my output is


-80.265905,43.159700,0

now i need to take the -80.265905 and store it in a variable called Long
and need to store 43.159700 in a variable called Lat

the '0' can be discarded...

I looked al the list function but cant get it to work
 
this is weird

I had this working since last week but now im getting an error
Code:
 <cfset xml=cfhttp.FileContent>
 <cfset xmlDoc = XMLParse(xml)>
 <cfset xml=xmlparse(xmlDoc)>
 <cfset myvalue=xml.kml.response.placemark.point.coordinates.xmltext>

Error:
Element KML.RESPONSE.PLACEMARK.POINT.COORDINATES.XMLTEXT is undefined in XML.


i have not changed anything in the code...just stopped working

Craig
 
you don't have the element defined.
you can try

<cfif IsDefined('xml.kml.response.placemark.point.coordinates.xmltext')>
<cfset myvalue=xml.kml.response.placemark.point.coordinates.xmltext>
<cfelse>
<cfset myValue='oh no!'>
</cfif>



 
its ok...got it...

it generates that error if the address it is looking up is invalid...


hmmm which leads me to my next question, how would I get around that little problem

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top