Accessing XML/PHP with period in tag

Posted by LuckyShot on Stack Overflow See other posts from Stack Overflow or by LuckyShot
Published on 2010-05-12T16:10:24Z Indexed on 2010/05/12 16:14 UTC
Read the original article Hit count: 208

Filed under:
|
|

Hi guys,

Quick newbie question here, how do I access totalResults?

XML

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription>
  <opensearch:totalResults>1</opensearch:totalResults>
  <posts>
    <post>
      <score>10</score>
    </post>
  </posts>
</OpenSearchDescription>

To access the score I would do this:

PHP

$xmlObj = simplexml_load_string($theXMLabove);
echo $xmlObj->posts->post[0]->score;

But none of these work for the totalResults:

echo $xmlObj->opensearch:totalResults;
echo $xmlObj->opensearch->totalResults;

Sorry for asking such a lame question...

Documentation on how to traverse XML with PHP is also appreciated :)

Thanks!

© Stack Overflow or respective owner

Related posts about Xml

Related posts about php