Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2011, 09:21 PM   PM User | #1
RamosDevil
New to the CF scene

 
Join Date: Dec 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
RamosDevil is an unknown quantity at this point
Displaying only Date from XML

Hey all,

I'm teaching myself XML while doing some freelance work, and have run into a problem. I'm pulling in an external .xml file and trying to pull just the date, but the XML has a pretty complex nomenclature for the date.

Code:
<pubDate>
<![CDATA[ Tue, 27 Dec 2011 13:46:09 EST ]]>
</pubDate>
I'm pulling this into my page using:

Code:
<script type="text/javascript">
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","/rss.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 

document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("item");
for (i=0;i<x.length;i++)
  { 
  document.write(x[i].getElementsByTagName("pubDate")[0].childNodes[0].nodeValue);
  }
document.write("</table>");
</script>
How do I make the script pull just the date? So instead of:

"Tue, 27 Dec 2011 13:46:09 EST"

it would should up as simply:

"December 27"

Thanks for the help in advance.
RamosDevil is offline   Reply With Quote
Old 12-28-2011, 11:15 AM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,856
Thanks: 9
Thanked 288 Times in 284 Posts
Dormilich is on a distinguished road
you need to parse the date (using JavaScript’s Date object) and extract the relevant information. what XML delivers is just the date string.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, rss, xml

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:09 PM.


Advertisement
Log in to turn off these ads.