0

I'm trying to access 'totalResults' from following xml which was returned by google(contacts)

 <generator version="1.0" uri="http://www.google.com/m8/feeds">Contacts</generator>
 <openSearch:totalResults>29</openSearch:totalResults>
 <openSearch:startIndex>1</openSearch:startIndex>
 <openSearch:itemsPerPage>25</openSearch:itemsPerPage>
Cheran
  • 1

2 Answers2

1

Try this PHP tutorial from the PHP docs on how to access attributes in XML:

<?php
$string = <<<XML
<a>
 <foo name="one" game="lonely">1</foo>
</a>
XML;

$xml = simplexml_load_string($string);
foreach($xml->foo[0]->attributes() as $a => $b) {
    echo $a,'="',$b,"\"\n";
}
?>

The above example will output:

name="one"
game="lonely"

Check this SO post for additional reference.

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
0
$xml = '<generator version="1.0" uri="http://www.google.com/m8/feeds">Contacts</generator>
 <openSearch:totalResults>29</openSearch:totalResults>
 <openSearch:startIndex>1</openSearch:startIndex>
 <openSearch:itemsPerPage>25</openSearch:itemsPerPage>'

$xml = simplexml_load_string($xml);
echo $xml->openSearch->totalResults;
Neeraj Kumar
  • 3,851
  • 2
  • 19
  • 41
  • Sorry , it didn't work. If you want to see the [full original xml file](http://www.unifiedvu.com/xerotest/simple.xml) – Cheran Jul 07 '17 at 06:38