Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,134
    Thanks
    12
    Thanked 332 Times in 328 Posts
    you need to parse the date (using JavaScript’s Date object) and extract the relevant information. what XML delivers is just the date string.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •