I am looking to parse a html page for a predefined string and then build a unique reference to that location. With the help of 'Wikken' I have come this far.. but it is not working quite correctly.
$d = new DOMDocument();
$d->loadXML($xml);
$x = new DOMXPath($d);
$result = $x->evaluate("//text()[contains(.,'STRING')]/ancestor::*/@id");
$unique = null;
for($i = $result->length -1;$i >= 0 && $item = $result->item($i);$i--){
if($x->query("//*[@id='".addslashes($item->value)."']")->length == 1){
echo 'Unique ID is '.$item->value."
";
$unique = $item->value;
break;
}
}
if(is_null($unique)) echo 'no unique ID found';
__EDIT_
Let me explain the problem again. I am looking to make a html parser that can parse a page and find a unique string. I then need to find a unique place holder for that location so that when the data on the website changes I can find the new data. Wrikken has helped me so far as to locating the string... unfortunately the code above does not find a unique css selector correctly.
Not sure if this is your problem, but I normally would do the first part more like this:
//*[contains(text(),'STRING')]/ancestor::*/@id