Contenido principal

matlab.io.xml.dom.DocumentConfiguration Class

Namespace: matlab.io.xml.dom

XML document normalization options

Since R2022a

Description

Use an object of the matlab.io.xml.dom.DocumentConfiguration class to specify the normalization options for an XML document. Creating a matlab.io.xml.dom.Document object creates a DocumentConfiguration 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 CDATA sections in the Document object, specified as a logical 1 (true) or 0 (false). When you specify:

  • 1 (true) — Include CDATA sections in the Document object.

  • 0 (false) — Omit CDATA sections from the Document object.

Whether to include comments in the Document object, specified as a logical 1 (true) or 0 (false). When you specify:

  • 1 (true) — Include comments in the Document object.

  • 0 (false) — Omit comments from the Document object.

Whether to normalize namespaces in the Document object, specified as a logical 1 (true) or 0 (false). When you specify:

  • 1 (true) — Normalize namespaces in the Document object.

  • 0 (false) — Do not normalize namespaces in the Document object.

Examples

collapse all

To specify the 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.

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 day from Monday through Friday, create an element named day and append the name of the day to the day element. Append the 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