} } } 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);