Parsing XML attributes within a namespace tag (PHP) -
Parsing XML attributes within a namespace tag (PHP) -
i'm using php , curl xml, i'm having problems accessing specific type of attributes.
say xml document this:
<item> <title>example title</title> <link>http://www.google.com</link> <description>sample desc here.</description> <media:content xmlns:media="http://mediaurl.com/" url="http://www.exampleurl.com/" type="image/jpeg" medium="image" height="226" width="571"> </media:content> </item> i want access url attribute within tag, can't seem around namespace problem.
currently, i've tried using:
$promos = $item->getelementbytagnamens("media", "content"); foreach ($promos $promo) { $promoimage = $promo->getattribute("url"); break; } echo $promoimage;
see http://www.php.net/manual/en/domdocument.getelementsbytagnamens.php. need register namespace namespaceuri in xml , specify it.
added
in origin didn't see you've got xmlns:media attribute in xml. need alter line
$promos = $item->getelementsbytagnamens("http://mediaurl.com/", "content"); php xml namespaces
Comments
Post a Comment