Skip to content
June 27, 2012 / Danii Oliver

How to parse XML or RSS node with a : colon

While building an RSS feed for a website update I ran into an XML node format that I had not encountered before.
I built the code in php and jQuery JavaScript to find a work around and end up with the code below that works.

in PHP you could try to ge the namespace and define it  foreach ($dom->getElementsByTagNameNS(‘http://api-url’, ‘*’) as $element) but it only worked when the xml was written in.

Basically you have to type  \\ to escape the colon or write as .find(“[nodeName=z:row]”) which is suppose to work in all modern browsers as webKit may have and issue with escaping the : colon


<title>Some Title Here</title>
<media:content url=”; medium=”image” height=”75″ width=”75″/>
<media:description>The Target Text</media:description>
<media:credit>Danii Oliver/Developer</media:credit>
<description>An and that I don’t want to show up.
&lt;a href=&quot;;p=1&quot;&gt;&lt;img alt=&quot;&quot; style=&quot;border: 0;&quot; border=&quot;0&quot; src=&quot;;p=1&quot;/&gt;&lt;/a&gt;

Working Code to parse XML

<script type=”text/javascript”>
type: “GET”,
url: “movies.rss”,
dataType: “rss”,
success: function(xml) {
var title = $(this).find(‘title’).text();
var link = $(this).find(‘guid’).text();
var description = $(this).find(‘media\\:description’).text();


var description = $(this).find(‘[nodeName=media:description]’).text(); **Did not work for me
$(‘#feeds’).append(‘<div class=”items”><a href=”‘+link+'”><h2>’+title+'</h2></a><p>’+description+'</p></div>’);


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: