Parse XML or HTML

Here’s a simple XML parser, with DOM Object, which can fetch values digging deep but in a few lines of code. It uses namespace functinality(XPATH). The XML document must have defined namespaces. <?php $xml = <<<EOT <?xml version=”1.0″ encoding=”UTF-8″?> <entry xmlns=”http://www.w3.org/2005/Atom” xmlns:other=”http://other.w3.org/other” > <id>uYG7-sPwjFg</id> <published>2009-05-17T18:29:31.000Z</published> </entry> EOT; $doc = new DOMDocument; $doc->loadXML($xml); $xpath = DOMXPath($doc); […]