Parses an XML string, xmlstr, and returns the corresponding Matlab structure v.
v = xml_parse(xmlstr)
v = xml_parse(xmlstr,attswitch)
This is a non-validating parser. XML processing entries or comments starting with '<?' or '<!', are ignored by the parser.
xmlstr
XML string, for example read from a file with
xmlstr =
fileread(filename)
attswitch optional,
default='on':
'on' reads XML header attributes idx,
size, type if
present and interprets these to create the correct Matlab data
types.
'off' ignores XML element header attributes and interprets contents
as strings.
v Matlab variable or structure.
This example shows how to define a simple XML string and parse it into a Matlab variable. As the idx, type, and size attributes are defined, the resulting Matlab data type conforms to these specifications (class double vector of size [1x2]).
xmlstr = ...
'<root idx="1" type="double" size="1 2">3.1416 1.4142</root>';
V1 = xml_parse(xmlstr)
V1 =
[3.1416, 1.4142] % (class double)
Again, setting the attswitch parameter to 'off' lets the parser ignore the attributes and the returned variable is interpreted as a string.
V2 = xml_parse(xmlstr,'off')
V2 =
'3.1416 1.4142' % (class char)
Let's define a more complex data set in XML:
xmlstr =
'<root>
<project>
<name>myProjectName</name>
<date>2004-09-13</date>
<bytes>10472</bytes>
</project>
<project>
<name>myProject Two</name>
<date>2004-09-13</date>
<bytes>9851</bytes>
</project>
</root>'
v = xml_parse(xmlstr);
v: 1x2 struct array with fields:
project
v(1).project:
name: 'myProjectName'
date: '2004-09-13'
bytes: '10472'
v(2).project:
name: 'myProject Two'
date: '2004-09-13'
bytes: '9851'
xml_parseany, xml_formatany, xml_format, xml_load, xml_save, xml_help
Copyright © 2007, The Geodise Project, University of Southampton