XML读取问题
XML code
第二个post 是关联第一个post的
怎么根据 <porid>tiid1</porid>值把第二post 下的所有节点取出来
<post> <type>1</type> <title id="tiid1">标题1</title> <porid></porid> <suname>Brand</suname> </post> <post> <type>1</type> <title>标题2</title> <porid>tiid1</porid> <suname>Brand</suname> </post>
第二个post 是关联第一个post的
怎么根据 <porid>tiid1</porid>值把第二post 下的所有节点取出来
作者: xiaopeng0803 发布时间: 2011-06-09
把所有post节点下的数据读取出来,然后循环,碰到porid节点为tiid1的时候,break,就ok了
作者: xiongmzh 发布时间: 2011-06-09
引用 1 楼 xiongmzh 的回复:
把所有post节点下的数据读取出来,然后循环,碰到porid节点为tiid1的时候,break,就ok了
把所有post节点下的数据读取出来,然后循环,碰到porid节点为tiid1的时候,break,就ok了
碰到proid为节点值为tiid1就break?? 怎么能读出下面内容呢?
XML code
<post> <type>1</type> <title>标题2</title> <porid>tiid1</porid> <suname>Brand</suname> </post>
作者: xiaopeng0803 发布时间: 2011-06-09
PHP code
输出:tiid1-标题2-Brand
$doc = new DOMDocument(); $doc->load('file.xml'); $posts= $doc->getElementsByTagName( "post" ); foreach( $posts as $post ) { $porids= $post ->getElementsByTagName( "porid" ); if($porids->item(0)->nodeValue == 'tiid1'){ $titles=$post->getElementsByTagName( "title" ); $sunames=$post->getElementsByTagName( "suname" ); echo $porids->item(0)->nodeValue.'-'. $titles->item(0)->nodeValue.'-'.$sunames->item(0)->nodeValue ; } }
输出:tiid1-标题2-Brand
作者: jordan102 发布时间: 2011-06-09
xpath="//post[porid='tiid1']"
作者: snmr_com 发布时间: 2011-06-09