skaterdav85 Posted March 25, 2010 Share Posted March 25, 2010 Im using simplexml to pull an rss feed. One of the xml tags however is <itunes:subtitle>, so if i try $item->itunes:subtitle in my foreach loop, PHP throws a syntax error. Anyone know how to get around this? I already tried using an escape character like this: $item->itunes\:subtitle but it didnt work. Link to comment Share on other sites More sharing options...
ScottyBoy Posted March 25, 2010 Share Posted March 25, 2010 I think you need to put a ; at the end of your code. $item->itunes:subtitle; Link to comment Share on other sites More sharing options...
boen_robot Posted March 25, 2010 Share Posted March 25, 2010 This is a namespaced node. You'll have to reach it with the children() method, by suppliying the namespace URI or prefix with the method's optional arguments. Link to comment Share on other sites More sharing options...
skaterdav85 Posted April 7, 2010 Author Share Posted April 7, 2010 This is a namespaced node. You'll have to reach it with the children() method, by suppliying the namespace URI or prefix with the method's optional arguments.I think you can only use the children method if you're getting the attribute of a tag, kind of like the examples on the link you sent me. My XML looks like this:<channel> <item> <itunes:author>Meghan McCoy</itunes:author> <itunes:subtitle>some subtitle</itunes:subtitle> </item></channel> this is my php, but it doesnt work. What did I do wrong? foreach($myXML->channel->item as $item) { echo "Subtitle: ".$item->children('itunes:subtitle')."<br/>";} Link to comment Share on other sites More sharing options...
boen_robot Posted April 7, 2010 Share Posted April 7, 2010 Look carefully at the description of the children() method. You need to supply information for the namespace, not for the element you're looking for. You need to say $item->children('itunes', true) or (what I'd reccomend you use) $item->children('http://www.itunes.com/dtds/podcast-1.0.dtd') Either of those is only going to get a collection of all elements in that namespace that are child of the current $item. You need to traverse this collection, and extract the information you need from it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.