Main Content

matlab.io.xml.dom.DOMWriter class

Package: matlab.io.xml.dom

Writer that serializes an XML document

Description

Use an object of the matlab.io.xml.dom.DOMWriter class to create a writer that serializes an XML document.

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

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

example

writer = matlab.io.xml.dom.DOMWriter() creates a writer to serialize a matlab.io.xml.dom.Document object. Use the Configuration property to specify writer options.

Properties

expand all

Writer options, specified as a matlab.io.xml.dom.WriterConfiguration object.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Data Types:

Methods

expand all

Examples

collapse all

Write an XML document to a file using a matlab.io.xml.dom.DOMWriter object.

Create an XML document as a matlab.io.xml.dom.Document object.

import matlab.io.xml.dom.*
docNode = Document("root_element");
docRootNode = getDocumentElement(docNode);
weekdays = ["Mon" "Tue" "Wed" "Thu" "Fri"];
weekdaysElement = createElement(docNode,"weekdays");
for i=1:5
    dayElement = createElement(docNode,"day");
    appendChild(dayElement,createTextNode(docNode,weekdays(i)));
    appendChild(weekdaysElement,dayElement);
end
appendChild(docRootNode,weekdaysElement);

Create a writer to serialize the XML document.

xmlFileName = "weekdays.xml";
writer = matlab.io.xml.dom.DOMWriter;

Save the XML document to a file.

writeToFile(writer,docNode,xmlFileName);
Introduced in R2021a