0

UPDATE: I don't believe this is an exact duplicate because my question is dealing specifically with SimpleXmlElement and gives a clear example with my XML and even a reference to the class. The question you believe my duplicate is refers to: simplexml_load_file and not SimpleXmlElement. Also it does not give a clear example with code like mine does. The answer given in the alleged is not very clear for my purposes. Finally the duplicate question answer gives dead links in the code so we can't see the example code.

I did figure out the answer: $length = $entry->children('itunes', TRUE)->duration;

Please consider opening up this question again so I can offer this clear example to others. - Thanks –

Using php SimpleXmlElement how can I get a xml tag with colon in it? Example: <itunes:duration>33:00</itunes:duration>

Here is info on the SimpleXmlElement Class

Here is a sample item from the XML I am accessing:

<item>
            <title>7th Video Exposing Planned Parenthood Is Released - The Terry and Jesse Show - August 19, 2015</title>
            <pubDate>Wed, 19 Aug 2015 12:00:00 +0000</pubDate>
            <guid isPermaLink="false"><![CDATA[140b435c9de567175da347928406caeb]]></guid>
            <link><![CDATA[http://saintjoepodcast.libsyn.com/7th-video-exposing-planned-parenthood-is-released-the-terry-and-jesse-show-august-19-2015]]></link>
            <itunes:image href="http://static.libsyn.com/p/assets/0/7/5/9/0759313aabd1b45e/jesse-n-terry_banner-new.png" />
            <description><![CDATA[]]></description>
            <enclosure length="26345472" type="audio/mpeg" url="http://traffic.libsyn.com/saintjoepodcast/The_Terry_and_Jesse_Show_-_August_19_2015_-_7th_Video_Exposing_Planned_Parenthood_Is_Released.mp3" />
            <itunes:duration>58:02</itunes:duration>
            <itunes:explicit>no</itunes:explicit>
            <itunes:keywords />
            <itunes:subtitle><![CDATA[]]></itunes:subtitle>
</item>

Below is the php where I can abstract a simple xml tag, like 'Title', but how do I get the info of an tag that has a colon in it? Example: <itunes:duration>33:00</itunes:duration>

FULL PHP:

<?
$content = file_get_contents("http://saintjoepodcast.libsyn.com/rss");
$x = new SimpleXmlElement($content);

echo "<nav><ul>";  
foreach($x->channel->item as $entry)
     {
      echo "<li><a href='$entry->link' title='$entry->title'>" .  $entry->title  . "</a></li>";   
     }
echo "</ul></nav>";
?>
Papa De Beau
  • 3,744
  • 18
  • 79
  • 137
  • "XML tag with a colon in it" is an XML namespace (in this case iTunes). This may help your search. (perhaps `$sxElement->attributes($ns)` could work). Have you tried reading it with `$entry->{'itunes:duration'}`? – h2ooooooo Aug 26 '15 at 19:25
  • Just tried $entry->{'itunes:duration'}. That didn't seem to work. Good idea tho. – Papa De Beau Aug 26 '15 at 19:29
  • You have the option to ask for the question to be reopened use it if you think you are right. But have a good read of the thing I think is duplicated – RiggsFolly Aug 26 '15 at 19:59
  • @PapaDeBeau But the `->children()` method still exists, so it should be possible. Are you asking if there's a *better* way? – h2ooooooo Aug 26 '15 at 20:03
  • Thanks RiggsFolly, well one thing the answer in the duplicate gives a dead link. http://www.sitepoint.com/recent.rdf so we can't even see an example of the code he was referring to. I can't get the answer still. I know it's in the right direction but not exactly what I need. – Papa De Beau Aug 26 '15 at 20:04
  • h2ooooooo, I can't figure out the answer. I don't know if I use $entry->itunes->children('duration') or $entry->children('ituens') etc... – Papa De Beau Aug 26 '15 at 20:06
  • I found the answer from the link I gave. Not from the so called duplicate question. Here is the answer: $length = $entry->children('itunes', TRUE)->duration; Please consider an 'upvote' for reopening so I can give the right answer for others. My code has examples. The duplicate answer offers dead links etc... – Papa De Beau Aug 26 '15 at 20:20
  • Actually the namespace is not `itunes` but `http://www.itunes.com/dtds/podcast-1.0.dtd`, `itunes` is just an alias for it, called a namespace prefix. The better call would be `$entry->children('http://www.itunes.com/dtds/podcast-1.0.dtd')`. Namespace prefixes are optional and can change. – ThW Aug 26 '15 at 20:36
  • So how do I access then? – Papa De Beau Aug 26 '15 at 20:49

0 Answers0