%% Create a CDATA Section to Output Unescaped Markup Characters
% This example shows the difference between the serialized output from markup characters in a Text node and CDATASection node. The example creates a Text node and CDATASection node with text content that includes the markup characters > and <. The output from the Text node represents the markup characters as entities. The output from the CDATASection node includes the unescaped markup characters.
% Create a Document object and get the root element.

import matlab.io.xml.dom.*

docNode = Document("root_element");
docRootNode = getDocumentElement(docNode);

% Create a Text node that contains the code x > 1 | x < 2. Append the node to the root element.

tn = createTextNode(docNode,'x > 1 | x < 2');
appendChild(docRootNode,tn);

% Create a CDATASection node that contains the same code and append the node to the root element.

cdata = createCDATASection(docNode,'x > 1 | x < 2');
appendChild(docRootNode,cdata);

% Write the XML to a string.

str = writeToString(DOMWriter,docNode)

%
% Copyright 2020 The MathWorks, Inc.