Main Content

mlreportgen.utils.tidy

Correct and clean XML and HTML content

Description

example

outString = mlreportgen.utils.tidy(inString) corrects and cleans an XHTML string. Correcting adds missing end tags. Cleaning removes unnecessary tags.

example

outFile = mlreportgen.utils.tidy(inFile) corrects and cleans an XHTML file.

___ = mlreportgen.utils.tidy(___,Name=Value) uses additional options specified by one or more Name-Value pair arguments.

Examples

collapse all

outString = mlreportgen.utils.tidy...
   ("<p>sample input string with missing end tag")
outString = 

    "<html xmlns="http://www.w3.org/1999/xhtml">
     <head>
     <title></title>
     </head>
     <body>
     <p>sample input string with missing end tag</p>
     </body>
     </html>
     "

For this example, substitute your username in the "c:\Users\username\Documents\myHTMLFile.html" string.

outFile = mlreportgen.utils.tidy("myHTMLFile.html",...
   OutputFile="C:\Users\username\Documents\myHTMLFile.html");
outFile = 

      "C:\Users\username\Documents\myHTMLFile.html"
     

Assume that you have created your own configuration file, named myConfig.cfg, and stored it in your Documents folder while you test it. For ease of finding the file later, store it in the same location as the default configuration files or store it with your output file.

For this example, substitute your username in the "c:\Users\username\Documents\myNewHTMLFile.html" string.

outFile = mlreportgen.utils.tidy("myHTMLFile.html",...
    OutputFile="c:\Users\username\Documents\myNewHTMLFile.html",...
    ConfigFile="myConfig.cfg");
outFile = 

      "C:\Users\username\Documents\myHTMLFile.html"
     

Input Arguments

collapse all

HTML text to correct and clean, specified as a character vector or string scalar.

HTML file to correct and clean, specified as a character vector or string scalar.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: tidy("myFile.html",OutputType="html")

Type of output file, specified as a character vector or string scalar. Valid values are 'xml', 'html', and 'xhtml'. To ensure that the tidied file is XML compliant, use 'xhtml' as the output type.

Path of output file, specified as a character vector or string scalar. If the file is in the current working folder, you can specify only the file name, otherwise specify the full path. The tidied output file can overwrite the original HTML file or be saved to a new file.

Configuration file, specified as a character vector or string scalar. The configuration file contains options for cleaning and correcting input strings and files. (For more information, see External Links.) Default configuration files for each output type are located in the <matlabroot>/toolbox/shared/mlreportgen/utils/resources folder. The files are tidy-html.cfg, tidy-xml.cfg, and tidy-xhtml.cfg. You can create your own configuration file and specify it using this parameter. The easiest way to create your own configuration file is to copy the default file, make your changes, and save it using a new file name. If you specify your own ConfigFile, it overrides the OutputType parameter.

Note

The indentation of the tidied file is set to false in the default configuration file. To turn on indentation, create your own configuration file and set indent to true.

Output Arguments

collapse all

Tidied XHTML, returned as a string that contains the basic elements of an HTML file.

Tidied XHTML file, returned as a string that indicates the file location and name.

Version History

Introduced in R2018b