The simplest thing to do is use DOMXPath::querydocsDOMXPath::querydocs
The following code finds all the <field> nodes within <row> nodes that have a name attribute equal to "header":
$dom = new DOMDocument; $dom->loadXML($str); // where $str is a string containing your sample xml $xpath = new DOMXPath($dom); $query = "//row/field[@name='header']"; $elements = $xpath->query($query); foreach ($elements as $field) { echo $field->nodeValue, PHP_EOL; } Using the sample xml you provide, the above outputs:
blah blah 1 blah blah 2