本文整理汇总了PHP中SimpleXMLElement::XPath方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLElement::XPath方法的具体用法?PHP SimpleXMLElement::XPath怎么用?PHP SimpleXMLElement::XPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::XPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foreach
}
}
}
if ($keywordId = $search->searchKeyword($keyword, $keywordsXML)) {
//Searchs keyword in list and returns 'ID', if exists;
$databaseXML = simplexml_load_file("../data/database/{$keyword['0']}.xml");
$links = $databaseXML->XPath("/data/keyword[@id={$keywordId}]");
// print_r($links);
foreach ($links[0]->children() as $link) {
$att = 'id';
$urlID = $link->attributes()->{$att};
$att = 'domain';
$domainID = $link->attributes()->{$att};
$att = 'occur';
$occurrence = $link->attributes()->{$att};
if (!($result = $xml->XPath("/results/result[url/@id = {$urlID} and url/@domain = {$domainID}]"))) {
//Insert new result;
$new_result = $xml->addChild('result');
$new_result->addChild('title');
$url = $new_result->addChild('url');
$url->addAttribute('id', $urlID);
$url->addAttribute('domain', $domainID);
$weight = $new_result->addChild('weight');
$words = $new_result->addChild('words');
$word = $words->addChild('word', $keyword);
$word->addAttribute('count', $occurrence);
} else {
//Modify old result;
$words = $result[0]->words;
$word = $words->addChild('word', $keyword);
$word->addAttribute('count', $occurrence);