mlreportgen.utils.tidy class

Package: mlreportgen.utils
Superclasses:

Correct and clean XML and HTML content

Construction

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

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

Input Arguments

expand all

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

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

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

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

You can also use strings to specify name-value pair arguments.

Type of output file, specified as a string or character vector. 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 string or character vector. 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 string or character vector. 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

expand 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.

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"
     

Introduced in R2018b