2009-01-10 92 views
0

試圖找到一個XML文件,我可以用它來代替查找數據庫表,直到我們的虛擬主機切換到正確的數據庫。郵政編碼到城市/州查找XML文件?

任何人都可以向我推薦一個XML文件,其中的子元素的子代碼是郵政編碼,州和城市?例如: -

<zip code="98117"> 
    <state>WA</state> 
    <city>Seattle</state> 
</zip> 

或者

<entry> 
    <zip>98117</zip> 
    <state>WA</state> 
    <city>Seattle</city> 
</entry> 
我會在C#中使用LINQ查詢該數據

回答

0

有一個免費的郵編數據庫位於:

​​

我相信它的.CSV文件,但你可以將其轉換爲XML文件很容易。

0

以下是根據輸入的郵政編碼進行city.state自動填充的代碼。

<script type="text/javascript">//<![CDATA[ 
$(function() { 
    // IMPORTANT: Fill in your client key 
    var clientKey = "js-9qZHzu2Flc59Eq5rx10JdKERovBlJp3TQ3ApyC4TOa3tA8U7aVRnFwf41RpLgtE7"; 

    var cache = {}; 
    var container = $("#example1"); 
    var errorDiv = container.find("div.text-error"); 

    /** Handle successful response */ 
    function handleResp(data) 
    { 
     // Check for error 
     if (data.error_msg) 
      errorDiv.text(data.error_msg); 
     else if ("city" in data) 
     { 
      // Set city and state 
      container.find("input[name='city']").val(data.city); 
      container.find("input[name='state']").val(data.state); 
     } 
    } 

    // Set up event handlers 
    container.find("input[name='zipcode']").on("keyup change", function() { 
     // Get zip code 
     var zipcode = $(this).val().substring(0, 5); 
     if (zipcode.length == 5 && /^[0-9]+$/.test(zipcode)) 
     { 
      // Clear error 
      errorDiv.empty(); 

      // Check cache 
      if (zipcode in cache) 
      { 
       handleResp(cache[zipcode]); 
      } 
      else 
      { 
       // Build url 
       var url = "http://www.zipcodeapi.com/rest/"+clientKey+"/info.json/" + zipcode + "/radians"; 

       // Make AJAX request 
       $.ajax({ 
        "url": url, 
        "dataType": "json" 
       }).done(function(data) { 
        handleResp(data); 

        // Store in cache 
        cache[zipcode] = data; 
       }).fail(function(data) { 
        if (data.responseText && (json = $.parseJSON(data.responseText))) 
        { 
         // Store in cache 
         cache[zipcode] = json; 

         // Check for error 
         if (json.error_msg) 
          errorDiv.text(json.error_msg); 
        } 
        else 
         errorDiv.text('Request failed.'); 
       }); 
      } 
     } 
    }).trigger("change"); 
}); 

//]]>

這裏是API - http://www.zipcodeapi.com/Examples#example1

0

您可以通過XML請求內容通過直接以XML格式獲取數據,您可以使用請求格式中的.xml。

https://www.zipcodeapi.com/rest/RbdapNcxbjoCvfCv4N5iwB3L4beZg017bfiB2u9eOxQkMtQQgV9NxdyCoNCENDMZ/info.xml/90210/degrees

將與

<response> 
    <zip_code>90210</zip_code> 
    <lat>34.100501</lat> 
    <lng>-118.414908</lng> 
    <city>Beverly Hills</city> 
    <state>CA</state> 
    <timezone> 
    <timezone_identifier>America/Los_Angeles</timezone_identifier> 
    <timezone_abbr>PDT</timezone_abbr> 
     <utc_offset_sec>-25200</utc_offset_sec> 
     <is_dst>T</is_dst> 
    </timezone> 
    <acceptable_city_names/> 
</response> 

API文檔反應是在https://www.zipcodeapi.com/API

相關問題