matlab.io.xml.dom.Comment 类
包: matlab.io.xml.dom
创建对象
使用 matlab.io.xml.dom.Document
对象的 createComment
方法创建 matlab.io.xml.dom.Comment
对象。
属性
Length
— 注释中的字符数
双精度值
注释中的字符数,指定为双精度值。
属性:
GetAccess | public |
SetAccess | immutable |
Transient | true |
NonCopyable | true |
TextContent
— 注释的文本内容
字符向量
注释的文本内容,指定为字符向量。
属性:
GetAccess | public |
SetAccess | immutable |
Transient | true |
NonCopyable | true |
方法
公共方法
appendData |
以字符向量或字符串标量形式指定 |
cloneNode |
|
compareDocumentPosition |
要解码返回的值
例如: 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) 返回 '#comment' 。 |
getNodeTypeName | name = getNodeTypeName(thisComment) 返回 'COMMENT_NODE' 。 |
getNodeValue |
|
getOwnerDocument |
|
getParentNode |
|
getPreviousSibling |
|
getTextContent |
|
insertData |
|
isEqualNode | 如果 此方法测试节点的相等性,而不测试节点是否为同一对象的句柄。要测试相同性,请使用 相同的节点也会相等,但相等的节点未必相同。 在测试文档的相等性之前对它们进行标准化,因为标准化会影响相等性。 |
isSameNode | 如果 |
replaceData |
将 |
setData |
以字符向量或字符串标量形式指定 |
setNodeValue |
以字符向量或字符串标量形式指定 |
setTextContent |
以字符向量或字符串标量形式指定 |
splitText |
|
substringData |
将 |
示例
向文档添加注释
此示例向表示一周中星期几的 XML 文档的根节点添加注释。
使用名为 weekdays
的根元素创建 matlab.io.xml.dom.Document
对象。
import matlab.io.xml.dom.* doc = Document("weekdays"); docRootNode = getDocumentElement(doc);
使用 Document
对象的 createComment
方法创建注释。将该注释追加到根元素。
appendChild(docRootNode,createComment(doc,"days of the week except Saturday and Sunday"));
对于一周中的每个工作日,即从星期一到星期五,创建一个名为 day
的元素,并将该天的名称追加到 day
元素中。将 day
元素追加到根元素。
weekdays = ["Mon" "Tue" "Wed" "Thu" "Fri"]; for i=1:5 dayElement = createElement(doc,"day"); appendChild(dayElement,createTextNode(doc,weekdays(i))); appendChild(docRootNode,dayElement); end
将文档写入文件 weekdays.xml
;
xmlFileName = "weekdays.xml";
writer = matlab.io.xml.dom.DOMWriter;
writer.Configuration.FormatPrettyPrint = true;
writeToFile(writer,doc,xmlFileName);
显示文件内容。
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>
注释 <!--days of the week except Saturday and Sunday-->
紧跟在根元素 weekdays
的开始标记之后。
版本历史记录
在 R2021a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 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)