我需要查询xml文档,然后显示特定的标记值,例如forename,surname,group(dept),job_title .
我正在使用XMLReader,因为我可能需要处理大型XML文件 . 我使用DomXPath过滤数据,但我不知道如何检索每个元素的nodeName和值 . 下面的代码只返回'member'作为节点名称?
任何帮助,将不胜感激 .
<?php
$reader = new XMLReader();
$reader->open('include/staff.xml');
while ($reader->read()){
switch($reader->nodeType){
case(XMLREADER::ELEMENT):
if($reader->localName === 'staff'){
$node = $reader->expand();
$dom = new DomDocument();
$dom->formatOutput = true;
$n = $dom->importNode($node, true);
$dom->appendChild($n);
$xp = new DomXpath($dom);
$res = $xp->query("/staff/member[groups='HR']");
}
}
}
echo $res->item(0)->nodeName;
echo $res->item(0)->nodeValue;
?>
2 回答
还是有点粗糙,但这就是我所追求的 . 我发现我的xpath查询导致了问题 .
?>
尝试
和
根据这个页面,它们应该是"The qualified name of the node"和"The text value of the node" http://www.php-editors.com/php_manual/ref.xmlreader.html
显然这就是人们如何使用它:http://www.google.com/codesearch/p?hl=pl#_rn0kgFhkQA/redir/docvert/60463/url_tgz/docvert-3.2.3.tar.gz%7CP-uLGAoGHyM/docvert/core/process/ParseOpenDocument.php&q=xmlreader%20file:%5C.php $
也许更多的使用示例可以在这里找到:http://www.google.com/codesearch?q=xmlreader+file:.php $