0

How is this done?

i read about it here: CDATA I've tried:

    var XML = document.createElement("testing");
    var NodeSystemOut = document.createElement("system-out");
    var cdata = document.createCDATASection
    ('<p>Good relations have I with the Wookies</p>');
    NodeSystem.appendChild(cdata);
    XML.appendChild(NodeSystem); 

but this does not work.

any ideas? javascript noob

5
  • possible duplicate of Javascript to add cdata section on the fly? Commented Jan 15, 2013 at 19:41
  • i can't get that example to work... in the link you posted.. Commented Jan 15, 2013 at 20:00
  • doc.createCDATASection is working for me from that example (where doc is a valid XML document instance) Commented Jan 15, 2013 at 20:26
  • @tkone i'm generating an xml document in a string, so this does not work for me.... if you had a look at the code above you'd realize that it will through an exception since i'm not loading in an xml file or document... Commented Jan 15, 2013 at 20:28
  • You shouldn't be using the document.createElement API to create XML unless document is an XML document. Which unless you've gone through specific lengths to do so will NOT let you use createCDATASection. Look through the answer linked for a better example of how to do what you're trying to do. Commented Jan 15, 2013 at 20:32

1 Answer 1

1

Is there a newline in your runtime code?

var cdata = document.createCDATASection
('<p>Good relations have I with the Wookies</p>');

Check that your JavaScript engine doesn't interpret these as two separate expressions. This is a perfectly legal line of JavaScript:

("");

Confusingly, JavaScript supports implicit semicolon expression delimiters.

So, the engine might be assigning cdata to a function reference:

var cdata = document.createCDATASection;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.