Main Content

matlab.io.xml.dom.Parser Class

Namespace: matlab.io.xml.dom

XML markup parser

Since R2021a

Description

Use an object of the matlab.io.xml.dom.Parser class to convert XML markup to a matlab.io.xml.dom.Document object. A Parser object has two methods for converting XML If the XML is in a file, use the parseFile method to convert the XML markup. If the XML is in character vector or string scalar, use the parseString method.

The XML markup to be parsed must contain only one top-level element, which can be preceded or followed by a comment or processing instruction. If the markup contains more than one top-level element, the parser throws an error after processing the first element. The parser reports comment or processing instruction expected as the reason for the error.

The matlab.io.xml.dom.Parser class is a handle class.

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

parser = matlab.io.xml.dom.Parser() creates an XML markup parser. Use the Configuration property to specify parser options.

example

Properties

expand all

Parser options, specified as a matlab.io.xml.dom.ParserConfiguration object.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Methods

expand all

Examples

collapse all

Create a parser and call the parseFile method to convert the XML in a file to a matlab.io.xml.dom.Document object.

import matlab.io.xml.dom.*

doc = parseFile(Parser,"days.xml");

Create a parser and call the parseString method to convert an XML string to a matlab.io.xml.dom.Document object.

import matlab.io.xml.dom.*
s1 = "<days><day>Mon</day><day>Tue</day><day>Wed</day>";
s2 = "<day>Thu</day><day>Fri</day></days>";
xmlString = s1+s2;
doc = parseString(Parser,xmlString);

Limitations

  • A Parser object cannot parse a file if the input XML file contains an <xi> tag.

Version History

Introduced in R2021a

expand all