Main Content

matlab.io.xml.transform.ResultString Class

Namespace: matlab.io.xml.transform

Store transformation result as string

Since R2021a

Description

Use an object of the matlab.io.xml.transform.ResultString class to store the results of an XML transformation as a string scalar. You can provide a ResultString object to the transform method of a matlab.io.xml.transform.Transformer object.

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

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

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

example

Properties

expand all

Text that contains transformation results, specified as a string scalar.

Attributes:

GetAccess
public
SetAccess
private
GetObservable
true
SetObservable
true

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.ResultString object.

The 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 ResultString object.

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

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

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

View the string in the ResultString object.

resultObj.String
ans = 
    "<html>
     <body>
     <table>
     <tr>
     <th>Country</th><th>Capital</th>
     </tr>
     <tr>
     <td>Canada</td><td>Ottawa</td>
     </tr>
     <tr>
     <td>France</td><td>Paris</td>
     </tr>
     <tr>
     <td>Peru</td><td>Lima</td>
     </tr>
     </table>
     </body>
     </html>
     "

Version History

Introduced in R2021a