Converts a Matlab variable into an XML string with user-defined attributes.



xmlstr = xml_formatany(v)

xmlstr = xml_formatany(v,attswitch)

xmlstr = xml_formatany(v,attswitch,name)



xml_formatany converts Matlab variables and structures (including deeply nested structures) into an XML string. The user can specify attributes for each XML element in substructures of the struct variable, v.


Input Arguments

v                   Matlab variable of type "struct", "char", "double"(numeric), "complex", "sparse", "cell", or "logical"(boolean).

attswitch optional, default='on':
'on' writes header attributes idx, size, type for identification by Matlab when parsing the XML later;
'off' writes "plain" XML without header attributes.

name            optional, give root element a specific name, eg. 'project'.


Output Arguments

xmlstr        string, containing XML description of the variable v.


The root element of the created XML string is called 'root' by default but this can be overwritten with the name input parameter. A default xml_tb_version attribute is added to the root element unless attswitch is set to 'off'.


If attswitch is left empty, [], or set to 'on', the default attributes idx, type, and size will be added to the XML element headers. This allows xml_parse to parse and convert the XML string correctly back into the original Matlab variable or data structure.


If attswitch is set to 'off', some of the information is lost and subsequently the contents of XML elements will be read in as strings when converting back using xml_parse.



In this example, we define a data structure in Matlab and add attributes to it before converting it into an XML string.


v.project.name = 'my Project no. 002';
v.project.date = datestr(now, 31);
v.project.uid  = '2004-0909-1618-29af-04c7';

v.project.ATTRIBUTE.id = 'AA5119278466';
v.comment.CONTENT = 'This is a new project';

v.comment.ATTRIBUTE.fontname = 'Times New Roman';

xmlstr = xml_formatany(v);


xmlstr =

  <project id="AA5119278466">

    <name>my Project no. 002</name>

    <date>2004-09-09 16:18:29</date>



  <comment fontname="Times New Roman">This is a new




If attributes are required for string data, the string must be explicitly assigned to a CONTENT field of the Matlab structure. In the above example, the comment field is defined as

comment.ATTRIBUTE.fontname = 'Times New Roman'

comment.CONTENT = 'This is a new project';

This is due to the ATTRIBUTE field overwriting the contents otherwise.


See also

xml_parseany, xml_format, xml_parse , xml_load, xml_save, xml_help




Copyright © 2007, The Geodise Project, University of Southampton