Main Content

matlab.io.xml.dom.ProcessingInstruction Class

Namespace: matlab.io.xml.dom

XML processing instruction

Since R2021a

Description

Use an object of the matlab.io.xml.dom.ProcessingInstruction class to provide data to an application that processes the XML document that embeds the processing instruction. For example, you can use a processing instruction to specify the location of the stylesheet used to transform the XML document.

Note

A ProcessingInstruction object inherits methods and properties from the matlab.io.xml.dom.Node class that are ineffective or cause errors when used with a ProcessingInstruction object. Use only the methods and properties that are documented on this page.

The matlab.io.xml.dom.ProcessingInstruction class is a handle class.

Class Attributes

ConstructOnLoad
true
HandleCompatible
false

For information on class attributes, see Class Attributes.

Creation

Use the createProcessingInstruction method of a matlab.io.xml.dom.Document object to create a matlab.io.xml.dom.ProcessingInstruction object. Specify the target and data in the method call. For example:

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

Properties

expand all

Processing instruction target, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Processing instruction data, specified as a character vector or string scalar.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Methods

expand all

Examples

collapse all

Suppose that an application that transforms XML uses a processing instruction in the XML to locate the stylesheet. To create the processing instruction, use the createProcessingInstruction method of the matlab.io.xml.dom.Document object. Provide the application name as the target argument and the stylesheet path as the data argument.

Create a document with a root element named book.

import matlab.io.xml.dom.*

doc = Document('book');

Create a processing instruction and specify that the target is stylesheet and the data is href = "myStylesheet.xsl". Append the processing instruction to the document.

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

Write the XML to the file book.xml.

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

Display the XML.

type book.xml;
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><book/><?stylesheet href = "myStylesheet.xsl"?>

Version History

Introduced in R2021a