$root = $dom->documentElement;
$items = $root->childNodes;

解决方案 »

  1.   

    TO LS:我想取的是items下的a结点的value,不用getelmentbytagname,请问还有什么方法?类似asp的childnode(0).nodevalue这种,谢谢LS了~
      

  2.   

    有啊,一样用 $node->childNodes->item(0)->nodeValue;
      

  3.   

    TOLS:我想想啊...应该是 $root->childNodes  $items(0)->childNodes->item(0)->nodeValue;
    请问是这样么?
      

  4.   

    TOLS:xpath我也试过,还是只能取到item这级别,后面的不用tagname不知道没有什么办法了...请LS能不能详细解答,谢谢
      

  5.   

    问题在于xml的写法要是
    <root><item><a>11</a><b>1</b><c>0</c></item></root>如果写成
    <root>
    <item>
    <a>11</a>
    <b>1</b>
    <c>0</c>
    </item>
    </root>
    是完全不同的DOM结构,回车符号都算作是Node的如果是第一种写法
    $dom = new DOMDocument();
    $dom->load('result.xml');
    $root = $dom->documentElement;
    $items = $root->childNodes;
    $item = $items->item(0);
    $itemChildren = $item->childNodes;
    $b = $itemChildren->item(1);
    echo $b->nodeValue;
      

  6.   

    TOLS:晕...真不知道这两种XML还有区别啊....谢谢LZ了....我回去试试....长见识了,谢谢.
    那第二种改怎么写呢?
      

  7.   

    请问有高手知道第二种XML怎么读么?不用TAGNAME。。谢谢了阿第一种hookee兄帮我解决了希望有高手解答谢谢
      

  8.   

    php5的话,用simplexml_load_file,很方便.
      

  9.   

    第二种就调整Item的索引数呀。$item = $items->item(1);
      

  10.   

    TOLS:貌似直接这样子不行..反正我这里报错说nodeelement没有item方法...如果LS设置正确请告诉我方法...
      

  11.   

    //method 1
    $dom = new DOMDocument();
    $dom->load("result.xml");
    $xmlPath = new DOMXPath($dom);
    echo $xmlPath->query('/root/item/a')->item(0)->textContent;
    //method 2
    $xml = simplexml_load_file("result.xml");
    print_r($xml);
    echo $xml->item[0]->a;