Main Content

matlab.io.xml.dom.WriterConfiguration class

Package: matlab.io.xml.dom

XML DOM writer options

Description

Use properties of a matlab.io.xml.dom.WriterConfiguration object to specify options for an XML DOM writer represented as a matlab.io.xml.dom.DOMWriter object. A WriterConfiguration object is created when you create a matlab.io.xml.dom.DOMWriter object. Use the Configuration property of the DOMWriter object to access the WriterConfiguration object.

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

Class Attributes

HandleCompatible
true
ConstructOnLoad
true

For information on class attributes, see Class Attributes.

Properties

expand all

Whether to pretty-print the output XML markup, specified as true or false. If the value is true, the writer formats the output by adding whitespace to produce the output in an indented, human-readable form.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Whether to include an XML declaration in the output, specified as true or false. If the value is true, the writer includes an XML declaration in the output.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Whether to include a Document Type Definition (DTD) in the output, specified as true or false, if the value is true, and the DOM document contains a Document Type Declaration (DTD), the writer includes the DTD in the XML file output.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Whether to include a byte order mark (BOM) in the output. If the value is true, the writer includes a BOM at the beginning of the XML file output stream.

The writer includes a BOM only if it is writing to a file and the output encoding is one of these encodings:

  • UTF-8

  • UTF-16

  • UTF-16LE

  • UTF-16BE

  • UCS-4

  • UCS-4LE

  • UCS-4BE

For UTF-16 and UCS-4 encodings, the endian mode of the host machine is used to determine the BOM.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Whether to discard default content in the output, specified as true or false. If the value is true, the writer uses available information, such as an XML schema, DTD, and the specified flag on Attr nodes, to decide which attributes and content to discard. If the value is false, the writer keeps all attributes and content.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Whether to split CDATA sections, specified as true or false. If the value is true, the writer splits CDATA sections that contain the CDATA section termination marker ']]>' or unrepresentable characters in the output encoding. If the value is false, the writer throws an error if a CDATA section contains a CDATA section termination marker ']]>' or an unrepresentable character.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Examples

collapse all

Write an XML document to a file and format the XML output so that it is indented and readable.

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;

Specify pretty-print formatting.

writer.Configuration.FormatPrettyPrint = true;
writeToFile(writer,docNode,xmlFileName);

View the formatted file.

type(xmlFileName);
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<root_element>

  <weekdays>
    <day>Mon</day>
    <day>Tue</day>
    <day>Wed</day>
    <day>Thu</day>
    <day>Fri</day>
  </weekdays>

</root_element>
Introduced in R2021a