xmlImportOptions
Description
An XMLImportOptions
object enables you to specify how
MATLAB® imports structured, tabular data from XML files. The object contains properties
that control the data import process, including the handling of errors and missing data.
Creation
You can create an XMLImportOptions
object using either the
xmlImportOptions
function (described here) or the detectImportOptions
function:
Use
xmlImportOptions
to define the import properties based on your import requirements.Use
detectImportOptions
to detect and populate the import properties based on the contents of the XML file specified infilename
.opts = detectImportOptions(filename)
Syntax
Description
opts = xmlImportOptions
creates an
XMLImportOptions
object with one variable.
opts = xmlImportOptions('NumVariables',
creates the object with the number of variables specified in
numVars
)numVars
.
opts = xmlImportOptions(___,
specifies additional properties for an
Name,Value
)XMLImportOptions
object using one or more name-value
arguments.
Input Arguments
Properties
Examples
Tips
Use XPath selectors to specify which elements of the XML input document to import. For example, suppose you want to import the XML file
myFile.xml
, which has the following structure:This table provides the XPath syntaxes that are supported for XPath selector name-value arguments, such as<data> <table category="ones"> <var>1</var> <var>2</var> </table> <table category="tens"> <var>10</var> <var>20</var> </table> </data>
VariableSelectors
orTableSelector
.Selection Operation Syntax Example Result Select every node whose name matches the node you want to select, regardless of its location in the document. Prefix the name with two forward slashes ( //
).data = readtable('myFile.xml', 'VariableSelectors', '//var')
data = 4×1 table var ___ 1 2 10 20
Read the value of an attribute belonging to an element node. Prefix the attribute with an at sign ( @
).data = readtable('myFile.xml', 'VariableSelectors', '//table/@category')
data = 2×1 table categoryAttribute _________________ "ones" "tens"
Select a specific node in a set of nodes. Provide the index of the node you want to select in square brackets ( []
).data = readtable('myFile.xml', 'TableSelector', '//table[1]')
data = 2×1 table var ___ 1 2
Specify precedence of operations. Add parentheses around the expression you want to evaluate first. data = readtable('myFile.xml', 'VariableSelectors', '//table/var[1]')
data = 2×1 table var ___ 1 10
data = readtable('myFile.xml', 'VariableSelectors', '(//table/var)[1]')
data = table var ___ 1
Version History
Introduced in R2021a