现在有个URL,访问其会返回一个从浏览器打开xml文件,
现在怎么将该xml读取下来,或者说将该xml内容保存在本地。可以的话给shell脚本命令也行,谢谢!!!

解决方案 »

  1.   

      public org.xml.sax.InputSource(java.lang.String uri);在命令行下可以使用 cURL。
      

  2.   

    curl "http://www.google.com/ig/api?weather=beijing&hl=zh-cn" | iconv -f gbk -t utf-8
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  1326    0  1326    0     0   1832      0 --:--:-- --:--:-- --:--:--  3526
    <?xml version="1.0"?><xml_api_reply version="1"><weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" ><forecast_information><city data="Beijing, Beijing"/><postal_code data="beijing"/><latitude_e6 data=""/><longitude_e6 data=""/><forecast_date data="2011-10-05"/><current_date_time data="2011-10-06 03:30:00 +0000"/><unit_system data="SI"/></forecast_information><current_conditions><condition data="晴"/><temp_f data="57"/><temp_c data="14"/><humidity data="湿度: 77%"/><icon data="/ig/images/weather/sunny.gif"/><wind_condition data="风向: 东北、风速:2 米/秒"/></current_conditions><forecast_conditions><day_of_week data="周三"/><low data="8"/><high data="26"/><icon data="/ig/images/weather/sunny.gif"/><condition data="晴"/></forecast_conditions><forecast_conditions><day_of_week data="周四"/><low data="7"/><high data="23"/><icon data="/ig/images/weather/sunny.gif"/><condition data="晴"/></forecast_conditions><forecast_conditions><day_of_week data="周五"/><low data="10"/><high data="23"/><icon data="/ig/images/weather/sunny.gif"/><condition data="晴"/></forecast_conditions><forecast_conditions><day_of_week data="周六"/><low data="15"/><high data="26"/><icon data="/ig/images/weather/mostly_sunny.gif"/><condition data="以晴为主"/></forecast_conditions></weather></xml_api_reply>
      

  3.   


    这个必须是linux下吗,我在win7命令行怎么不行
      

  4.   

    你说shell,我还以为你是linux。在http://curl.haxx.se/download.html这里下载curl,windows版在页面最下方,拖到底后,选择合适的版本下载。
      

  5.   

    windows shell 可以使用powershell
    http://stackoverflow.com/questions/1819341/how-to-read-xml-file-from-web-using-powershell
      

  6.   

     麻烦了,请问如果直接想读取通过访问URL返回的xml,采用哪个比较好,大概是什么样的步骤!!
    谢谢
      

  7.   

    java.net.URL 不是有 openStream方法,
      

  8.   

    然后呢URL url=new URL(URL_ALL);
    URLConnection urlConnection = url.openConnection();
    DataInputStream urlDis = new DataInputStream(urlConnection.getInputStream());
    Document doc = builder.build(urlDis);
    Element root = doc.getRootElement();
    List child = root.getChildren();这样一个节点一个节点读吗
      

  9.   

    结贴了:2种方法
    1:
    URLConnection urlConnection = url.openConnection();
    InputStream urlIn = urlConnection.getInputStream();
    doc = reader.read(urlIn);
    2:用httpClient皆可