Skip to main content
Inspiring
June 11, 2009
Question

DOM Scripting - accessing XML CDATA values

  • June 11, 2009
  • 1 reply
  • 642 views

HI Folks,


Not sure if this is the write forum, but I'm trying to use Javascript to output XML values onto my webpage, see below.

This works fine, but when I try and get he values in a CDATA tag, I get undefined or null.

Can anyone please tell me how to get CDATA content?

<script type="text/javascript"

xmlDoc=loadXMLDoc("news.xml");

x=xmlDoc.getElementsByTagName('title');
for (i=0;i<x.length;i++)
{
document.write(x.childNodes[0].data);
document.write("<br />");
}
</script>

XML

<items>
  <item>
    <title>
      <![CDATA[text goes in here]]>
    </title>
</item>
</items>
    This topic has been closed for replies.

    1 reply

    Participating Frequently
    June 12, 2009

    I think you will have more success on a JavaScript forum.

    Mack

    matthiscoAuthor
    Inspiring
    June 12, 2009

    Thanks