Main Content

matlab.io.xml.dom.ProcessingInstruction 类

命名空间: matlab.io.xml.dom

XML 处理指令

自 R2021a 起

描述

使用 matlab.io.xml.dom.ProcessingInstruction 类的对象向处理嵌入有处理指令的 XML 文档的应用程序提供数据。例如,您可以使用处理指令来指定用于转换 XML 文档的样式表的位置。

注意

ProcessingInstruction 对象会从 matlab.io.xml.dom.Node 类继承方法和属性,但某些方法和属性在与 ProcessingInstruction 对象结合使用时无效或者会导致错误。请仅使用本页公开的方法和属性。

matlab.io.xml.dom.ProcessingInstruction 类是一个 handle 类。

类属性

ConstructOnLoad
true
HandleCompatible
false

有关类属性的信息,请参阅类属性

创建对象

使用 matlab.io.xml.dom.Document 对象的 createProcessingInstruction 方法创建 matlab.io.xml.dom.ProcessingInstruction 对象。在方法调用中指定目标和数据。例如:

pi = createProcessingInstruction(doc,'stylesheet','href = "myStylesheet.xsl"');

属性

全部展开

处理指令目标,指定为字符向量。

属性:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

处理指令数据,指定为字符向量或字符串标量。

属性:

GetAccess
public
SetAccess
public
NonCopyable
true

方法

全部展开

示例

全部折叠

假设转换 XML 的应用程序使用 XML 中的处理指令来定位样式表。要创建处理指令,请使用 matlab.io.xml.dom.Document 对象的 createProcessingInstruction 方法。提供应用程序名称作为 target 参量,提供样式表路径作为 data 参量。

创建一个具有名为 book 的根元素的文档。

import matlab.io.xml.dom.*

doc = Document('book');

创建一个处理指令,并指定目标为 stylesheet,数据为 href = "myStylesheet.xsl"。将处理指令追加到文档中。

pi = createProcessingInstruction(doc,'stylesheet','href = "myStylesheet.xsl"');
appendChild(doc,pi);

将该 XML 写入文件 book.xml

xmlFileName = 'book.xml';
writer = matlab.io.xml.dom.DOMWriter;
writeToFile(writer,doc,xmlFileName);

显示该 XML。

type book.xml;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book [
<!ENTITY chapter SYSTEM "chapter.xml">
]>
<book>
    &chapter;
</book>

版本历史记录

在 R2021a 中推出