-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>';
1

1 Answer 1

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");
...
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @SparK at-Gordon That Worked..:)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.