Correct and clean XML and HTML content
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"
inString
— HTML text to correct and cleanHTML text to correct and clean, specified as a string or character vector.
inFile
— HTML file to correct and cleanHTML file to correct and clean, specified as a string or character vector.
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
.
tidy("myFile.html","OutputType","html")
'OutputType'
— Type of output fileType 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.
'OutputFile'
— Path of output filePath 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.
'ConfigFile'
— Configuration fileConfiguration 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
.
outString
— Tidied XHTML stringTidied XHTML, returned as a string that contains the basic elements of an HTML file.
outFile
— Tidied XHTML fileTidied XHTML file, returned as a string that indicates the file location and name.