Main Content

matlab.io.xml.transform.SourceFile Class

Namespace: matlab.io.xml.transform

XML source file for transformation

Since R2021a

Description

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

The matlab.io.xml.transform.SourceFile 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.SourceFile(path) creates a matlab.io.xml.transform.SourceFile object with the Path property set to the specified path.

example

Properties

expand all

Path of XML file, 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.SourceFile 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 SourceFile object, sourceObj, that contains the XML source for the transformation.

import matlab.io.xml.transform.*
sourceObj = SourceFile("capitals.xml");

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 Web browser.

web("capitals.html")

Here is the HTML table:

Version History

Introduced in R2021a