能循环出xml节点下的数据.可以节点下又有节点.不知道怎么读了.- <result>
- <item>
- <segment>
  <bookno>PBN9959</bookno> 
  <bookcode>VVN</bookcode> 
- <class>
  <c>FADYGKHTQLSNMEBURJVZIPXW</c> 
  <a>52SAQQQQQQQQQQQQASASS3AS</a> 
  </class>
  </segment>
  </item>
- <item>
- <segment>
  <bookno>PBN3151</bookno> 
  <bookcode>VVX</bookcode> 
- <class>
  <c>FAPYTKHMGSLQUEVBXNR</c> 
  <a>4Q2AQQQQQQQQAQQQQAQ</a> 
  </class>
  </segment>
  </item>
  </result>
php解析代码.部分省略了$doc->loadXML($mystrs);
$Node_Record =$doc->getElementsByTagName("item"); 
$Node_Record_Length  =$Node_Record->length;
$K=0;
for ($c=0;$c<$Node_Record_Length;$c++)
{

$K=0;
foreach ($Node_Record->item($c)->childNodes as $articles)

$Field[$K]=$articles->textContent;
$K++;
}
          }
这样读出来以后.<c>和<a>就连接到一起了.请问怎么取<c>和<a>节点的数据..

解决方案 »

  1.   

    php解析那里getElementsByTagName读节点误写了.应该是$Node_Record =$doc->getElementsByTagName("segment"); 
      

  2.   

    DOMNodeList DOMDocument::getElementsByTagName ( string $name )
      

  3.   

    $xml = simplexml_load_file(“xxx.xml”);XML代码:<?xml version="1.0" encoding="GBK" ?> 
    - <result tag="success">
      <username>weiyg</username> 
      <uid>358066</uid> 
      <money>0</money> 
    - <gameUserList gameServerID="5" count="1">
      <gameuser username="damimi123" password="123456" extend="" /> 
      </gameUserList>
      </result>  用 $xml = simplexml_load_file(“xxx.xml”);print_r($xml)是数据输出数据格式类似stdClass   SimpleXMLElement Object 

        [@attributes] => Array 
            ( 
                [tag] => success 
            )     [username] => weiyg 
        [uid] => 358066 
        [money] => 0 
        [gameUserList] => SimpleXMLElement Object 
            ( 
                [@attributes] => Array 
                    ( 
                        [gameServerID] => 5 
                        [count] => 1 
                    )             [gameuser] => SimpleXMLElement Object 
                    ( 
                        [@attributes] => Array 
                            ( 
                                [username] => damimi123 
                                [password] => 123456 
                                [extend] => 
                            )                 )         ) )
      运用$uid = $xml->uid; 
    $isbind = $xml->gameUserList->attributes()->count; //是否绑定, 
    $tag =  $xml->attributes(); //返回是否成功 这种方式即可取得各节点或者属性的值。参见
    http://blog.studclub.cn/post/238.html