Main Content

matlab.io.xml.dom.Element Class

Namespace: matlab.io.xml.dom

Element of XML document

Since R2021a

Description

An object of the matlab.io.xml.dom.Element class represents an XML markup tag.

The matlab.io.xml.dom.Element 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.dom.Element object by using the createElement or createElementNS method of a matlab.io.xml.dom.Document object.

Properties

expand all

Child nodes of this element, specified as a 1-by-N array of matlab.io.xml.dom objects.

Attributes:

GetAccess
public
SetAccess
immutable
NonCopyable
true
Transient
true

Tag name of this element, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
immutable
NonCopyable
true
Transient
true

Text content of this element, specified as a character vector or string scalar. This property contains the concatenated textual content of this node and its children.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Whether this element has attributes, specified as true or false.

Attributes:

GetAccess
public
SetAccess
immutable
NonCopyable
true
Transient
true

Methods

expand all

Examples

collapse all

This example creates matlab.io.xml.dom.Element and matlab.io.xml.dom.Text objects to represent XML markup for weekdays.

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 and the root element weekdays.

doc = Document("weekdays");
weekdaysElement = getDocumentElement(doc);

Create a string array of the text for each weekday.

weekdays = ["Mon" "Tue" "Wed" "Thu" "Fri"];

For each weekday, create an Element object for the day element and a Text object for the day text. Append the Text object to the day element and the day element to the weekdays element.

for i=1:5
    dayElement = createElement(doc,"day");
    appendChild(dayElement,createTextNode(doc,weekdays(i)));
    appendChild(weekdaysElement,dayElement);
end

Write the XML to a file.

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

Version History

Introduced in R2021a