Main Content

matlab.io.xml.transform.SourceString Class

Namespace: matlab.io.xml.transform

XML source string for transformation

Since R2021a

Description

Use an object of the matlab.io.xml.transform.SourceString class to specify a string as the source XML markup for a transformation. You can provide a SourceString object as an input to the transform or transformToString method of a matlab.io.xml.transform.Transformer object.

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

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

sourceObj = matlab.io.xml.transform.SourceString(markup) creates a matlab.io.xml.transform.SourceString object with the String property set to the specified XML markup.

example

Properties

expand all

XML markup, specified as a string scalar or character vector.

Attributes:

GetAccess
public
SetAccess
public
GetObservable
true
SetObservable
true

Examples

collapse all

This example transforms the XML markup for countries and their capital cities into an HTML table. The example specifies the input XML as a matlab.io.xml.transform.SourceString object.

The example uses capitals.xsl as the stylesheet for the transformation.

<?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 SourceString object, sourceObj, to contain the XML source for the transformation.

import matlab.io.xml.transform.*
s1 = "<Countries><Country><Name>Canada</Name>";
s2 = "<Capital>Ottawa</Capital></Country></Countries>";
XMLText = s1 + s2; 
sourceObj = SourceString(XMLText);

Perform the transformation and provide sourceObj as the XML source, capitals.xsl as the stylesheet, and capitals.html as the name of the output file.

transform(Transformer,sourceObj,"capitals.xsl","capitals.html");

Open capitals.html in a browser.

web("capitals.html")

Here is the HTML table:

Version History

Introduced in R2021a