Wednesday, 23 January 2019

Changing CDATA sections into Text nodes

Changing CDATA sections into Text nodes?

Answer:

To change a CDATA section into a Text node, you have to copy the content of the CDATA section node into a string (using the data attribute that is inherited from the CharacterData interface). Create a Text node with that content (using the createTextNode method on the Documentinterface). Find the parent of the CDATASection node. Then replace the CDATA Section node with the Text node (either by inserting the Text node and deleting the CDATA Section node, or using the replaceChild method on the Node interface). You may then wish to call the normalize method (on Element in Level 1, but on Node in Level 2), to merge any adjacent Text nodes.

See also the parameter "cdata-sections" in the DOMConfiguration interface provided by DOM Level 3.

No comments:

Post a Comment