Получение пути через DOMXPath

$a = "<body><head><title>Page Title</title></head></body>";
$dom = new DOMDocument('1.0', 'utf-8');
$dom->preserveWhiteSpace = false;
$dom->loadXML($a);
$xpath = new DOMXPath($dom);
$arts = $xpath->query("/body/head/title");

foreach($arts as $art) {
    echo $art->nodeName . " - " . $art->nodeValue . "<br />";
}

Comments are closed.