Hi I have a simple XML feed, which returns the data in the format shown below
<Computers>
<results totalPages="18" currentPage="18" totalResults="88"/>
<computer id="1" name="IBM">
<computertype id="1" name="Windows"/>
</computer>
<computer id="94" name="Acer">
<computertype id="1" name="windows"/>
</computer>
<computer id="1533" name="selfbuild">
<computertype id="1" name="windows"/>
</computer>
</computers>
to display the results i use the following
foreach($xml->computer as $computer){
echo $computer['name'];
What i am trying to do is get the result of the total pages, current page and total results in to variables, the problem i have is that when i try and write them as below, it isn’t returning a result.
echo $results['totalPages'];
I think it is because the foreach is starting after the results section, but if i try and write them as below, again i get nothing.
foreach($xml->results as $results){
echo $results['totalPages'];
Any advice would be appreciated.
Thanks
You’re trying to access the attributes of a node.
Do it like this, using SimpleXML:
Which outputs the following:
Or access each attribute directly: