[ create a new paste ] login | about

Link: http://codepad.org/JX8RpaKu    [ raw code | output | fork ]

PHP, pasted on Apr 3:
<?php
$xml = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
<entry>
        <id>uYG1-sPwjFg</id>
        <published>2009-05-17T18:29:31.000Z</published>
</entry>
<entry>
        <id>uYG2-sPwjFa</id>
        <published>2009-05-18T18:29:31.000Z</published>
</entry>
<entry>
        <id>uYG3-sPwjFb</id>
        <published>2009-05-19T18:29:31.000Z</published>
        <slash:comments>5</slash:comments>
</entry>
</feed>
EOT;

$doc = new DOMDocument;
$doc->loadXML($xml);
$xpath = new DOMXPath($doc);

$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
$xpath->registerNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/');

$result =  $xpath->evaluate('string(//atom:entry[3]/slash:comments)');

print $result;
?>


Output:
1
5


Create a new paste based on this one


Comments: