Extracting CDATA Using jQuery

Posted by George L Smyth on Stack Overflow See other posts from Stack Overflow or by George L Smyth
Published on 2010-03-31T14:34:28Z Indexed on 2010/03/31 17:23 UTC
Read the original article Hit count: 488

Filed under:
|
|

It looks like this has been asked before, but the answers do not appear to work for me. I am outputting information from a local XML file, but the description elements is not being output because it is enclosed in CDATA - if I remove the CDATA portion then things work fine.

Here is my code:

$(document).ready(
  function() {
    $.get('test.xml',
      function($info) {
        objInfo = $($info);

        objInfo.find('item').slice(0,5).each(
          function() {
            var Guid = $(this).find('guid').text();
            var Title = $(this).find('title').text();
            var Description = $(this).find('description').text();
            $('#Content').append(
              "<p><a href='" + Guid + "'>" + 
              Title + "</a>&nbsp;" +
              Description +
              "</p>"
            )
          }
        );

      },
      'xml'
    );
  }
)

Any idea how I can successfully extract Description information that is wrapped in CDATA?

Thanks -

george

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about Xml