ptim
March 13, 2019, 11:39am
1
Hello friends,
I have a partial XML string that i would like to parse:
<item>
<title>Some title</title>
<link>http://www.url/</link>
<description>Sample desc</description>
<guid>http://www.url/</guid>
<pubDate>Wed, 13 Mar 2019 10:06:13 +0100</pubDate>
<dc:creator>Tim</dc:creator>
<media:content type="image/jpeg" url="http://www.url/">
<media:credit scheme="urn:ebu">Timi</media:credit>
<media:description>Image description</media:description>
</media:content>
</item>
I have tried to get the url attribute of media:content but failed, have tried with
$xml = simplexml_load_string($xmlstr);
$media = $xml->xpath("//media:content");
var_dump((string) $media[0]->attributes()->url);
and
var_dump((string) $xml->media['url']);
But none seem to be able to get the attribute url of media:content.
Is this because its a partial XML? Because it gives some warnings on namespace errors.
Is there any other approach that could work, I do not need the have the XML validated.
YiuJia
March 13, 2019, 12:46pm
2
$xml->{āmedia:contentā}[āurlā]
1 Like
ptim
March 13, 2019, 12:58pm
3
Thank you so much for your help! works like a charm!!
ptim
March 13, 2019, 11:43pm
4
Is there any way to āsearchā for the media:content url?
I have another xml where the media:content is inside another tag
<media:group>
<media:content type="image/jpeg" url="http://www.url/">
</media:group>
YiuJia
March 14, 2019, 6:17am
5
A link for examples on simplexml :
http://php.net/manual/en/simplexml.examples-basic.php
this should work : $xml->{āmedia:groupā}->{āmedia:contentā}[āurlā]
Or you can use xpath (you have an example on the link i give)
YiuJia:
Voici un petit lien sympa.
http://php.net/manual/en/simplexml.examples-basic.php
sinon un truc du genre : $xml->{āmedia:groupā}->{āmedia:contentā}[āurlā] devrait fonctionner.
Ou tu peux utiliser le xpath (tu as un exemple dāutilisation dans le lien que je tāai donnĆ©)ā¦
For the benefit of other users, please translate your post otherwise I believe it will be removed.
Edit:
Thank you
system
Closed
June 13, 2019, 1:50pm
7
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.