我知道load('sixx.xml'); //读取xml文件 $Results = $doc->getElementsByTagName( "Record" ); foreach($Results as $Result){ $Records = $Result->getElementsByTagName("Item"); $times = $Records->item(0)->nodeValue; } 定位到Item继续操作 都是没有利用id的,我想知道如果利用XML的ID取数据改怎么办? 我有尝试用getElementById()获取,提示没有这个方法。。。 Call to undefined method DOMElement::getElementById()。 求大神帮忙解答一下,谢谢。 回复讨论(解决方案) $s =XML;$xml = simplexml_load_string($s);$t = $xml->xpath('//*[@Id="8"]');print_r($t);登录后复制 Array( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [Id] => 8 ) [Value] => 13.94 ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [Id] => 8 ) [Value] => 13.86 ))登录后复制 这是我的xml文件(文件名是6.xml),我想用SimpleXML处理文档,但是为什么取不出去数据? 代码如下: $xml = simplexml_load_file('6.xml'); foreach( $xml->Item as $a ){ echo $a->Value; } ?> 运行结果是空的。。我觉得代码没有问题啊。。 没有问题 Item as $a ){ echo $a->Value . '';}登录后复制 2011052413.8213.9413.7913.852011052513.8213.8613.5813.60登录后复制 使用simplexml_load_file 或 simplexml_load_string 就可以把xml转为数组了。 参考: http:// SimpleXMLElement Object ( [@attributes] => Array ( [Id] => 8 ) [Value] => 13.94 ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [Id] => 8 ) [Value] => 13.86 ) ) 来获取具体的数据, 我是利用echo $t -> Value; 和echo $t -> Id; 都无法获取数据。 XML的数组有些不懂,还望多多指教,感激不尽。
09-15 03:30