CDATA / Use Of This?
Jul 12, 2010What is the use of CDATA?
Explain me with a good example
What is the use of CDATA?
Explain me with a good example
How I can output the value of my xml below:
I'm trying to access the DOM of my xml file to display the content on a webpage.
I cant find a way to access the CDATA values in XML. code...
I want to read the parameters from CDATA within a HTML page, similar like the following code...
I can find the script element, but unfortunately I don't know how to proceed.
CDATA-blocks work great for coding large blocks of HTML, or CSS, into strings. But, I can't figure out how to use a variable-value within one.For example, consider this JavaScript code:
var FullName = "Friedrich Hayek";
var ProfileCode = (<><![CDATA[
<div id="BigHonkingChunkO_HTML">
[code]...
How do I get $FullName$ to render as "Friedrich Hayek" instead of "$FullName$"? Note that there is more than one variable and each variable can be used a few times in the CDATA block. Alternate code sample:
var UserColorPref = "red";
var UI_CSS = (<><![CDATA[
body {
[code]....
Looking to set the color attribute to red.
I am trying to access an HTML code stored as CDATA section in the xml file listed bellow:
<?xml version="1.0"?>
<results count="5">
<![CDATA[
<table><tr><td>Hello World</td></tr></table>
]]>
</results>
The xml tree is the responseXML part of an XmlHttpRequest and is stored
in a the javascript object xmldoc. While trying to test the node type
of the children of the "results"-Element I got different results with
IE and Mozilla: Code:
I'm receiving XML data via AJAX and the XML includes some CDATA values. The XML needs to be added to the page and then later scraped from the page and sent back as XML via AJAX.
Simple Example:
I receive -
And want to end up with:
And then send back as XML
99% of this is easy except the handling of the CDATA tag.
If I treat the XML as HTML, the CDATA tags get commented out automatically by JQuery.
So .html() returns <!--<![CDATA[Hello World]]>--> and .text() returns an null value (which is correct for a node containing only a comment).
If I treat the XML as XML, then .html() doesn't work making it impossible to insert the data (with its XML tags) into my page.
The only way around this I can see is to create a function that loops through the XML creating a HTML duplicate somehow and converting the CDATA nodes. When I want to send it back I have to reverse the process.
This seems a very long winded process when all I want to do is treat the XML as HTML except for the CDATA which needs to converted appropriately.
So two questions:
1) Am I missing some easy way to do all this using JQuery or other tools?
2) If I do need to manually convert the XML into HTML and vice versa, how do I do it?
I have an XML document that is returned which has an element named html. Inside of that element is a block of HTML wrapped with CDATA tags. I can alert the html variable that i create and see it has all of the data inside of it. So I want to parse through and grab certain things now. I'm just trying to get the element to return it's id to me, even though I know it ... because I kept getting the following error with other code.[code]
View 2 Replies View RelatedI have an XML document that is returned which has an element named html. Inside of that element is a block of HTML wrapped with CDATA tags. I can alert the html variable that i create and see it has all of the data inside of it. So I want to parse through and grab certain things now. I'm just trying to get the element to return it's id to me, even though I know it ... because I kept getting the following error.
I still continue to get this error with the current code below: