Main Content

matlab.io.xml.transform.ResultDocument Class

Namespace: matlab.io.xml.transform

Store transformation result as document

Since R2021a

Description

Use an object of the matlab.io.xml.transform.ResultDocument class to store the results of an XML transformation as a matlab.io.xml.dom.Document object. You can provide a ResultDocument object to the transform or transformToString method of a matlab.io.xml.transform.Transformer object.

The matlab.io.xml.transform.ResultDocument class is a handle class.

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

example

resultObj = matlab.io.xml.transform.ResultDocument() creates a matlab.io.xml.transform.ResultDocument object.

Properties

expand all

Document that results from a transformation, specified as a matlab.io.xml.dom.Document object.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Methods

expand all

Examples

collapse all

This example transforms the XML markup for countries and their capital cities into an HTML table. The transformation saves the result in a matlab.io.xml.transform.ResultDocument object.

This example uses these files:

  • capitals.xml

<Countries>
    <Country><Name>Canada</Name><Capital>Ottawa</Capital></Country>
    <Country><Name>France</Name><Capital>Paris</Capital></Country>
    <Country><Name>Peru</Name><Capital>Lima</Capital></Country>
</Countries>
  • capitals.xsl

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
      <table>
      <tr>
        <th>Country</th>
        <th>Capital</th>
      </tr>
      <xsl:for-each select="Countries/Country">
        <tr>
          <td><xsl:value-of select="Name"/></td>
          <td><xsl:value-of select="Capital"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

Create a ResultDocument object.

import matlab.io.xml.transform.*
resultObj = ResultDocument();

Perform the transformation and store the results in the ResultDocument object.

transform(Transformer,"capitals.xml","capitals.xsl",resultObj);

Access the document in the ResultDocument object.

getResult(resultObj)
ans = 
  Document with properties:

    InputEncoding: ''
      XMLEncoding: ''
    XMLStandalone: 0
       XMLVersion: ''
      DocumentURI: ''
    Configuration: [1×1 matlab.io.xml.dom.DocumentConfiguration]
      TextContent: ''
         Children: [1×1 matlab.io.xml.dom.Element]

Version History

Introduced in R2021a