Нужна помощь в разборке скрипта, написанного по мотивам
http://www.php.net/manual/en/function.xpath-eval.php и
http://www.providerz.ru/articles/php/xml-sax-dom-intro.html.
Скрипт достаточно прост, но в секции:
if (($contentNode->type==XML_ELEMENT_NODE) &&
(in_array($contentNode->name,array(\'title\',\'url\',\'time\',\'groupName\',\'groupUrl\')))) {
$currentNews[$contentNode->name] = $contentNode->content;
}не обрабатывается массив. Кто-то может дать дельный совет?
Собственно скрипт:
<?
$xmldata = "<?xml version=\\"1.0\\" encoding=\\"windows-1251\\"?>
<output>
<date>2002-10-12</date>
<news>
<title>Новость - 1</title>
<url>/news/1</url>
<time>09-10-2002 14:01</time>
<groupName>Section1</groupName>
<groupUrl>URL1</groupUrl>
<Body>
<![CDATA[ Тело новости из раздела 1 ]]>
</Body>
</news>
<news>
<title>Новость - 2</title>
<url>/news/2</url>
<time>09-10-2002 14:02</time>
<groupName>Section2</groupName>
<groupUrl>URL2</groupUrl>
<Body>
<![CDATA[ Тело новости из раздела 2 ]]>
</Body>
</news>
</output>";
$news = array();
$xml = xmldoc($xmldata);
$xml->xpath_init();
$ctx = xpath_new_context($xml);
$nodes = xpath_eval($ctx,\'//news/title | //news/url | //news/time | //news/groupName | //news/groupUrl\');
foreach($nodes->nodeset as $node)
{
$currentNews = array();
$content = $node->children();
foreach($content as $contentNode)
{
if (($contentNode->type==XML_ELEMENT_NODE) &&
(in_array($contentNode->name,array(\'title\',\'url\',\'time\',\'groupName\',\'groupUrl\')))) {
$currentNews[$contentNode->name] = $contentNode->content;
}
}
$news[] = $currentNews;
}
?>
<html>
<head>
<title>Output</title>
</head>
<body>
<table width=200 border=0>
<?
foreach($news as $n)
{
?>
<tr>
<td><b><?php echo "<a href=http://" . $n[\'url\'] . " target=_blank>" . $n[\'title\'] . "</a>\\n"; ?></b></td>
</tr>
<tr>
<td><?php echo "<a href=http://" . $n[\'groupUrl\'] . " target=_blank>" . $n[\'groupName\'] . "</a>\\n"; ?>
</td>
</tr>
<?
}
?>
</table>
</body>
</html>