Main Content

matlab.io.xml.dom.CDATASection class

Package: matlab.io.xml.dom

CDATA section

Description

An object of the matlab.io.xml.dom.CDATASection class defines an XML CDATA section. A CDATA section contains text content that is serialized without escaping XML markup characters.

A matlab.io.xml.dom.Parser object converts the markup <![CDATA[...]]> to a CDATASection object. You can use unescaped characters in the CDATA section markup. For example, you can use > instead of &gt;. CDATA section markup facilitates inclusion of computer code and mathematical expressions in XML documents by eliminating the need to use character entities to indicate >, <, and other characters.

The matlab.io.xml.dom.CDATASection class is a handle class.

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Create a matab.io.xml.dom.CDATASection object by using the createCDATASection method of a matlab.io.xml.dom.Document object.

Properties

expand all

Number of characters in the CDATA section, specified as a double.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Text content of the CDATA section, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
public

Methods

expand all

Examples

collapse all

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)
str = 
'<?xml version="1.0" encoding="UTF-16" standalone="no" ?><root_element>x &gt; 1 | x &lt; 2<![CDATA[x > 1 | x < 2]]></root_element>'
Introduced in R2021a