我對Zend Framework很新。我試圖獲得XML值,但不能使其工作。如何獲得標題?從這個XML使用Zend框架?
XML:
<?xml version="1.0" encoding="UTF-8"?>
<result count="2">
<blocks>
<listing>
<title>Title 1</title>
<id>1</id>
</listing>
<listing>
<title>Title 2</title>
<id>2</id>
</listing>
</blocks>
</result>
PHP(查找所有標題):
$dom = new Zend_Dom_Query();
$dom->setDocumentXml($result);
$results = $dom->queryXpath('/result/blocks/listing/title');
//$dom->queryXpath('/*/*/listing'); no luck
//$dom->queryXpath('///listing'); no luck
foreach($results as $k)
{
Zend_Debug::dump($k->getAttribute('title')); // empty
echo $k->getDocument(); // shows none
}
任何幫助嗎?
queryXpath('/ result/blocks/listing')那麼我也可以得到$ k-> nodeValue?我該如何$ K->標題>的nodeValue或$的k> ID->的nodeValue – YumYumYum
用SimpleXML可以使用'$父 - > child'語法,請參閱http://docs.php.net/SimpleXML – VolkerK