-4

Possible Duplicate:
How to get an attribute with SimpleXML?

I've a XML file which is stored as a PHP variable.

I've to extract tags addr & status value as a PHP variable from the xml string.

How to process it? It is dynamic and XML Tag attributes count also will be changing.

$xml='<?xml version="1.0"?>
<results>
<tags addr="http://a.com" status="yes">
<www addr="http://b.com" status="" status_source=""/>
<www addr="http://c.com" status="yes" status_source="None"/>
</tags>
<tags addr="http://d.com" status="no">
<www addr="http://e.com" status="" status_source=""/>
</tags>
<tags addr="http://f.com" status="no"/></tags>
<tags addr="http://g.com" status="no"/></tags>
</results>';
Community
  • 1
  • 1
Jenson M John
  • 5,499
  • 5
  • 30
  • 46
  • 1
    *(related)* [Best XML Parser for PHP](http://stackoverflow.com/questions/188414/best-xml-parser-for-php/3616044#3616044) – Gordon Oct 25 '11 at 08:05

1 Answers1

1

Using DOMDocument class you can make PHP read the XML and then look for the tag elements in it http://php.net/DOMDocument

Example

$document = new DOMDocument();
$document->loadXML($xml);

$tags = $document->getElementsByTagName("www");
...
SparK
  • 5,181
  • 2
  • 23
  • 32