<?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="" /> 
  <postal_code data="" /> 
  <latitude_e6 data="30670000" /> 
  <longitude_e6 data="104019996" /> 
  <forecast_date data="2009-12-24" /> 
  <current_date_time data="2009-12-24 17:00:00 +0000" /> 
  <unit_system data="SI" /> 
  </forecast_information>
- <current_conditions>
  <condition data="雾" /> 
  <temp_f data="43" /> 
  <temp_c data="6" /> 
  <humidity data="湿度: 93%" /> 
  <icon data="/ig/images/weather/cn_fog.gif" /> 
  <wind_condition data="风向: 北、风速:91 米/秒" /> 
  </current_conditions>
- <forecast_conditions>
  <day_of_week data="周四" /> 
  <low data="6" /> 
  <high data="14" /> 
  <icon data="/ig/images/weather/sunny.gif" /> 
  <condition data="晴" /> 
  </forecast_conditions>
- <forecast_conditions>
  <day_of_week data="周五" /> 
  <low data="3" /> 
  <high data="12" /> 
  <icon data="/ig/images/weather/sunny.gif" /> 
  <condition data="晴" /> 
  </forecast_conditions>
- <forecast_conditions>
  <day_of_week data="周六" /> 
  <low data="1" /> 
  <high data="11" /> 
  <icon data="/ig/images/weather/chance_of_rain.gif" /> 
  <condition data="可能有雨" /> 
  </forecast_conditions>
- <forecast_conditions>
  <day_of_week data="周日" /> 
  <low data="2" /> 
  <high data="10" /> 
  <icon data="/ig/images/weather/sunny.gif" /> 
  <condition data="晴" /> 
  </forecast_conditions>
  </weather>
  </xml_api_reply>
xml文件是通过URL获取的,怎样得到里面的属性值?各位帮帮忙

解决方案 »

  1.   


    $string = <<<XML
    <a xmlns:b>
     <foo name="one" game="lonely">1</foo>
    </a>
    XML;$xml = simplexml_load_string($string);
    foreach($xml->foo[0]->attributes() as $a => $b) {
        echo $a,'="',$b,"\"\n";
    }
      

  2.   

    $dom = simplexml_load_string($xml);
    print_r($dom);看看就知道了
      

  3.   

    dom节点
      

  4.   

    $xml中的字符得转义吧
      

  5.   

    http://www.google.com/ig/api?hl=zh-cn&weather=,,,30670000,104019996
    我就是要的到这个xml的数据,把hl=zh-cn&去掉就能得到......但是英文的.....
    是不是编码问题呢?
      

  6.   

    这样就可以了
    $s = file_get_contents('http://www.google.com/ig/api?hl=zh-cn&weather=,,,30670000,104019996');
    $dom = simplexml_load_string(iconv('gbk', 'utf-8', $s));
    print_r($dom);
      

  7.   

    编码有问题可用 simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><xml/>');