Main Content

matlab.io.xml.dom.Comment class

Package:matlab.io.xml.dom

评论in XML document

Description

An object of themlreportgen.io.xml.dom.Commentclass represents a comment in an XML document.

Thematlab.io.xml.dom.Commentclass is ahandleclass.

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, seeClass Attributes.

Creation

Create amatlab.io.xml.dom.Commentobject by using thecreateCommentmethod of amatlab.io.xml.dom.Documentobject.

Properties

expand all

Number of characters in the comment, specified as a double.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Text content of the comment, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Methods

expand all

Examples

collapse all

This example adds a comment to the root node of an XML document that represents the days of the week.

Create amatlab.io.xml.dom.Documentobject with a root element namedweekdays.

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

Use thecreateCommentmethod of theDocumentobject 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 nameddayand append the name of the day to thedayelement. Append thedayelements to the root element.

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

Write the document to the fileweekdays.xml;

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

Display the file contents.

typeweekdays.xml;
   Mon Tue Wed Thu Fri 

The commentimmediately follows the opening tag of the root elementweekdays.

Introduced in R2021a