I'm getting a website feed that looks like this
<rss...>
<title> some title </title>
<content>
<![CDATA[ <div>this tag is ignored<div> who took the cookie in the cookie jar!? ]]>
</content>
</rss>
I need the entire content of the cdata to be displayed in the html. I'm using jquery 1.9.1 and when I get the content part using $(xml).find('rss content').text()
,
it actually ignores the whole <div>this tag is ignored<div>
part. Any way to get everything inside the CDATA using javascript or jquery?
Note that CDATA sections should not be used within HTML; they only work in XML.
CDATA stands for Character Data and it tells the parser to copy the following code exactly (and not try to parse it.)
A CDATA section is used to mark a section of an XML document, so that the XML parser interprets it only as character data, and not as markup. It comes handy when one XML data need to be embedded within another XML document.
Note: CDATA is now deprecated. Do not use. The CDATA Section interface is used within XML for including extended portions of text. This text is unescaped text, like < and & symbols.
bottomline:
xmlDoc.getElementsByTagName("content")[0].childNodes[0].nodeValue
this snippet from working code uses jquery to load xml and then gets the 4th occurence of the content tag (which contains CDATA)
var req = new AjaxRequest();
req.setMethod("POST");
...
req.loadXMLDoc(linkString, paramString);
var htmlContent = req.getResponse().responseXML.getElementsByTagName('content').item(3).childNodes[0].nodeValue;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With