mlreportgen.utils.tidy
Correct and clean XML and HTML content
Syntax
Description
___ = mlreportgen.utils.tidy(___,
uses additional options specified by one or more Name=Value
)Name-Value
pair
arguments.
Examples
Tidy an Input String
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> "
Tidy and Overwrite Input File
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"
Write to New File and Use Custom Configuration File
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
inString
— HTML text to correct and clean
character vector | string scalar
HTML text to correct and clean, specified as a character vector or string scalar.
inFile
— HTML file to correct and clean
character vector | 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")
OutputType
— Type of output file
character vector | string scalar
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.
OutputFile
— Path of output file
character vector | string scalar
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.
ConfigFile
— Configuration file
character vector | string scalar
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
outString
— Tidied XHTML string
string scalar
Tidied XHTML, returned as a string that contains the basic elements of an HTML file.
outFile
— Tidied XHTML file
string scalar
Tidied XHTML file, returned as a string that indicates the file location and name.
Version History
Introduced in R2018b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)