3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str='<root> <book id="1"> <title>..1.</title> <author>.1..</author> </book> <book id="2"> <title>.2..</title> <author>.2..</author> </book> <book id="3"> <title>.3..</title> <author>.3..</author> </book> </root>'; $dom = new DOMDocument; $dom->loadXML($str); $xpath = new DOMXPath($dom); $book = $xpath->query("//book[@id='2']")->item(0); //$html = ""; foreach($book->childNodes as $node) { @$html .= $dom->saveHTML($node); } echo $html; ?>
based on 8YX1U
Output for 5.6.0 - 7.3.0alpha1
<title>.2..</title> <author>.2..</author>