matlab.io.xml.dom.Comment Class
Namespace: matlab.io.xml.dom
Description
An object of the mlreportgen.io.xml.dom.Comment
class represents a comment
in an XML document.
The matlab.io.xml.dom.Comment
class is a handle
class.
Class Attributes
ConstructOnLoad | true |
HandleCompatible | true |
For information on class attributes, see Class Attributes.
Creation
Create a matlab.io.xml.dom.Comment
object by using the
createComment
method of a matlab.io.xml.dom.Document
object.
Properties
Length
— Number of characters in comment
double
Number of characters in the comment, specified as a double.
Attributes:
GetAccess | public |
SetAccess | immutable |
Transient | true |
NonCopyable | true |
TextContent
— Text content of comment
character vector
Text content of the comment, specified as a character vector.
Attributes:
GetAccess | public |
SetAccess | immutable |
Transient | true |
NonCopyable | true |
Methods
Public Methods
appendData |
Specify
|
cloneNode |
|
compareDocumentPosition |
To decode the returned value,
For example: import matlab.io.xml.dom.* d = Document("root"); root = getDocumentElement(d); comment = createComment(d,"Example of a comment"); appendChild(root,comment); pos = compareDocumentPosition(comment,root); if bitor(pos,comment.DOCUMENT_POSITION_CONTAINS)... == pos disp("root contains comment"); else disp("root does not contain comment"); end |
deleteData |
|
getBaseURI |
|
getData |
|
getLength |
|
getNextSibling |
|
getNodeName | name = getNodeName(thisComment) returns
'#comment' . |
getNodeTypeName | name = getNodeTypeName(thisComment) returns
'COMMENT_NODE' . |
getNodeValue |
|
getOwnerDocument |
|
getParentNode |
|
getPreviousSibling |
|
getTextContent |
|
insertData |
|
isEqualNode |
This method tests for equality of
nodes, not whether the nodes are handles to the same object. To test for sameness,
use the Nodes that are the same are also equal, but nodes that are equal are not necessarily the same. Normalize documents before testing them for equality because normalization can affect equality. |
isSameNode |
|
replaceData |
Specify |
setData |
Specify |
setNodeValue |
Specify |
setTextContent |
Specify
|
splitText |
|
substringData |
Specify |
Examples
Add Comment to Document
This example adds a comment to the root node of an XML document that represents the days of the week.
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
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> <!--days of the week except Saturday and Sunday--> <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-->
immediately follows the opening tag of the root element weekdays
.
Version History
Introduced in R2021a
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)