Main Content

matlab.io.xml.dom.DocumentConfiguration Class

Namespace: matlab.io.xml.dom

Specify XML document normalization options

Since R2022a

Description

Use an object of matlab.io.xml.dom.DocumentConfiguration class to specify normalization options for an XML document represented as a matlab.io.xml.dom.Document object. A DocumentConfiguration object is created when you create a Document object. Use the Configuration property of the Document object to access the DocumentConfiguration object.

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

Class Attributes

Sealed
false
ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Properties

expand all

Whether to include CDATASections in the Document, specified as true or false.

Whether to include comments in the Document, specified as true or false.

Whether to normalize namespaces in the Document, specified as true or false.

Examples

collapse all

To specify document normalization options, modify the property values of the matlab.io.xml.dom.DocumentConfiguration object assigned to the Configuration property of the matlab.io.xml.dom.Document object. Use the normalizeDocument method to set the properties to the Document object.

This example configures the document to omit comments in the XML document.

Create a matlab.io.xml.dom.Document object with a root element named weekdays.

import matlab.io.xml.dom.*
doc = Document("weekdays");
docRootNode = getDocumentElement(doc);

Use the createComment method of the Document object to create a comment. Append the comment to the root element.

appendChild(docRootNode,createComment(doc,"days of the week except Saturday and Sunday"));

For each week day, Monday through Friday, create an element named day and append the name of the day to the day element. Append the day elements to the root element.

weekdays = ["Mon" "Tue" "Wed" "Thu" "Fri"];
for i=1:5
    dayElement = createElement(doc,"day");
    appendChild(dayElement,createTextNode(doc,weekdays(i)));
    appendChild(docRootNode,dayElement);
end
doc.Configuration.Namespaces = false;

Specify the document normalization options in the Configuration property. Use the nomalizeDocument method to set the normalization properties.

doc.Configuration.Comments = false;
normalizeDocument(doc);

Write the document to the file weekdays.xml.

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

Display the file contents.

type weekdays.xml
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<weekdays>
  <day>Mon</day>
  <day>Tue</day>
  <day>Wed</day>
  <day>Thu</day>
  <day>Fri</day>
</weekdays>

The comment <!--days of the week except Saturday and Sunday--> is removed from weekdays.xml.

Version History

Introduced in R2022a