2

Here is my XML fragment:

<?xml version="1.0" encoding="UTF-8"?>
<ns:searchResult xmlns:ns="http://outerx.org/daisy/1.0">
...
    <ns:rows>
        <ns:row documentId="1440-DFO_MPO" branchId="1" languageId="2"
            access="read,fullRead,write,publish">
            <ns:value>1440-DFO_MPO</ns:value>
            <ns:value>Navigation for Multimedia</ns:value>
        </ns:row>
    </ns:rows>
...

Here is my current PHP Code:

$dom = new DOMDocument();
$dom->load($xml);
$docs = $dom->getElementsByTagNameNS('http://outerx.org/daisy/1.0','row');

print "<ul>";
$c = 0;    
foreach ($docs as $elem) {
    print "<li>".$c."</li>";
    $c = $c + 1;
}    
print "</ul>";

AFAIK, this snippet should output a list of one item based on the XML fragment. However, it doesn't.

I've also tried (without success):

$docs = $dom->getElementsByTagName('row');

Edit #1 - Solution

Changed $dom->load($xml) to $dom->loadXML($xml);

0

1 Answer 1

2

Your code works for me. I assume you are passing the XML content in $xml when load() expects it to be a filename or URI. To load XML content directly you have to use

See http://codepad.org/oy3U1fmE

Sign up to request clarification or add additional context in comments.

1 Comment

I was loading XML directly. I changed to loadXML and voilà, it works. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.