2013-02-20 52 views
1

使用http://maps.googleapis.com/maps/api/geocode/xml?address=5555%20La%20Cienaga%20Blvd%20Los%20Angeles,%20CA&sensor=false解析谷歌地理編碼XML在傳統的ASP

我試圖在傳統的ASP解析XML。

我嘗試了不同的例子,他們想工作,但我不能

誰能給我個忙嗎? 例如,如果我想獲得「lat」和「formatted_address」的值,我該怎麼辦?

下面是我從鏈接獲得上述

<GeocodeResponse> 
<status>OK</status> 
<result> 
<type>street_address</type> 
<formatted_address>5555 La Cienega, Los Angeles, CA 90056, USA</formatted_address> 
<address_component> 
<long_name>5555</long_name> 
<short_name>5555</short_name> 
<type>street_number</type> 
</address_component> 
<address_component> 
<long_name>La Cienega</long_name> 
<short_name>La Cienega</short_name> 
<type>route</type> 
</address_component> 
<address_component> 
<long_name>Los Angeles</long_name> 
<short_name>Los Angeles</short_name> 
<type>locality</type> 
<type>political</type> 
</address_component> 
<address_component> 
<long_name>Los Angeles</long_name> 
<short_name>Los Angeles</short_name> 
<type>administrative_area_level_2</type> 
<type>political</type> 
</address_component> 
<address_component> 
<long_name>California</long_name> 
<short_name>CA</short_name> 
<type>administrative_area_level_1</type> 
<type>political</type> 
</address_component> 
<address_component> 
<long_name>United States</long_name> 
<short_name>US</short_name> 
<type>country</type> 
<type>political</type> 
</address_component> 
<address_component> 
<long_name>90056</long_name> 
<short_name>90056</short_name> 
<type>postal_code</type> 
</address_component> 
<geometry> 
<location> 
<lat>33.9978986</lat> 
<lng>-118.3696586</lng> 
</location> 
<location_type>RANGE_INTERPOLATED</location_type> 
<viewport> 
<southwest> 
<lat>33.9965523</lat> 
<lng>-118.3709990</lng> 
</southwest> 
<northeast> 
<lat>33.9992503</lat> 
<lng>-118.3683010</lng> 
</northeast> 
</viewport> 
<bounds> 
<southwest> 
<lat>33.9978986</lat> 
<lng>-118.3696586</lng> 
</southwest> 
<northeast> 
<lat>33.9979040</lat> 
<lng>-118.3696414</lng> 
</northeast> 
</bounds> 
</geometry> 
<partial_match>true</partial_match> 
</result> 
</GeocodeResponse> 

回答

1

的XML發起XML文檔在傳統的ASP,一旦你這樣做了嘗試使用XPath

Set docXML = CreateObject("Microsoft.XMLDOM") 
docXML.async = False 
docXML.loadXML(myXMLText) 

用於獲取緯度

docXML.documentElement.selectSingleNode("/GeocodeResponse/result/geometry/location/lat") 

and

docXML.documentElement.selectSingleNode("/GeocodeResponse/result/formatted_address") 

獲取格式化地址。

+0

謝謝!雖然我在看到你的帖子之前就已經明白了。 – user1567683 2013-03-01 16:18:04