解析XML问题,问题有两个:
1 为何$myXml->RESPONSE->FLAG解析不出数据
2 不会解析形如<F VL="20110101" VN="DATE" />的数据代码如下:
<?php
header("Content-Type: text/html; charset=utf-8");$xmlString = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<RESPONSE>
<FLAG>100</FLAG>
<CONTENT><LIST>
<F VL="88888" VN="SN" />
<F VL="20110101" VN="DATE" />
<F VL="张三" VN="NAME" />
</LIST></CONTENT>
</RESPONSE>
XML;$myXml = simplexml_load_string($xmlString);
//var_dump($myXml);
echo $myXml->RESPONSE->FLAG;
//echo $myXml->RESPONSE->CONTENT->NAME;
?>
上面的代码解析常见的xml是可以的,如:
[code=XML]
<?xml version="1.0" encoding="UTF-8"?>
<rss version="0.92">
<channel>
  <title>Mokka mit Schlag</title>
  <link>http://www.elharo.com/blog</link>
  <language>en</language>
  <item>
    <title>Penn Station: Gone but not Forgotten</title>
    <description>
     The old Penn Station in New York was torn down before I was born. 
     Looking at these pictures, that feels like a mistake.  The current site is 
     functional, but no more; really just some office towers and underground 
     corridors of no particular interest or beauty. The new Madison Square...
    </description>
    <link>http://www.elharo.com/blog/new-york/2006/07/31/penn-station</link>
  </item>
  <item>
    <title>Personal for Elliotte Harold</title>
    <description>Some people use very obnoxious spam filters that require you 
     to type some random string in your subject such as E37T to get through. 
     Needless to say neither I nor most other people bother to communicate with 
     these paranoids. They are grossly overreacting to the spam problem. 
     Personally I won't ...</description>    <link>http://www.elharo.com/blog/tech/2006/07/28/personal-for-elliotte-harold/</link>
  </item>
</channel>
</rss>
[code]先谢谢大家

解决方案 »

  1.   

    xml代码黏贴出问题了,再黏贴一次<?xml version="1.0" encoding="UTF-8"?>
    <rss version="0.92">
    <channel>
      <title>Mokka mit Schlag</title>
      <link>http://www.elharo.com/blog</link>
      <language>en</language>
      <item>
      <title>Penn Station: Gone but not Forgotten</title>
      <description>
      The old Penn Station in New York was torn down before I was born. 
      Looking at these pictures, that feels like a mistake. The current site is 
      functional, but no more; really just some office towers and underground 
      corridors of no particular interest or beauty. The new Madison Square...
      </description>
      <link>http://www.elharo.com/blog/new-york/2006/07/31/penn-station</link>
      </item>
      <item>
      <title>Personal for Elliotte Harold</title>
      <description>Some people use very obnoxious spam filters that require you 
      to type some random string in your subject such as E37T to get through. 
      Needless to say neither I nor most other people bother to communicate with 
      these paranoids. They are grossly overreacting to the spam problem. 
      Personally I won't ...</description>  <link>http://www.elharo.com/blog/tech/2006/07/28/personal-for-elliotte-harold/</link>
      </item>
    </channel>
    </rss>
      

  2.   

    参考
    http://topic.csdn.net/u/20081129/11/6f226b76-2495-4eb5-a98b-246564bfb07e.html
      

  3.   

    使用simpleXML,DOMDocument都可以解析复杂XML数据
      

  4.   

    问题已经解决,谢谢ihefe,结贴给分
    为何“为何$myXml->RESPONSE->FLAG解析不出数据”另外再开贴提问