Skip to main content
replaced http://us3.php.net with https://www.php.net
Source Link

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 

The simplest thing to do is use DOMXPath::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 

The simplest thing to do is use DOMXPath::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 
Source Link
user895378
user895378

The simplest thing to do is use DOMXPath::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