Main Content

matlab.io.xml.dom.Text Class

Namespace: matlab.io.xml.dom

Text in an XML document

Since R2021a

Description

An object of the matlab.io.xml.dom.Text class represents the text content of an XML document.

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

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Create a matlab.io.xml.Text object by using the createTextNode method of a matlab.io.xml.dom.Document object.

Properties

expand all

Number of characters in the text content of this node, specified as a double.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Text content of this text node, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Methods

expand all

Examples

collapse all

Create a text node to append to a document element by using the createTextNode method of the matlab.io.xml.dom.Document object that represents the document.

Import the matlab.io.xml.dom package so that you do not have to use long, fully qualified class names.

import matlab.io.xml.dom.*

Create a document with a root element named employee.

doc = Document("employee");
employeeElem = getDocumentElement(doc);

Create an element named jobtitle.

jobtitleElem = createElement(doc,"jobtitle");

Create a text node for the jobtitle text content and append the text note to the jobtitle element.

textNode = createTextNode(doc,"Manager");
appendChild(jobtitleElem,textNode);

Append the jobtitle element to the employeeElem element.

appendChild(employeeElem,jobtitleElem);

Write the XML to a file.

xmlFileName = "employee.xml";
writer = matlab.io.xml.dom.DOMWriter;
writeToFile(writer,doc,xmlFileName);

Version History

Introduced in R2021a