3.36585

3.4 | 45 ratings Rate this file 308 Downloads (last 30 days) File Size: 224.81 KB File ID: #4278

XML Toolbox

by Marc Molinari

 

17 Dec 2003 (Updated 20 Apr 2005)

Conversion of MATLAB data types to XML and vice versa.

| Watch this File

File Information
Description

The XML Toolbox converts MATLAB data structures of any level of nesting into an XML string. It also reads most types of XML strings/files and converts these into a Matlab structure.
Six simple functions are provided for this task:
xml_format()
xml_formatany()
xml_parse()
xml_parseany()
xml_load()
xml_save()
and help in xml_help.

This toolbox comes with an extensive pdf manual (35 pages).

Structures like this
>> project.name = 'MyProject';
>> project.id = 1234;
>> project.param.a = 3.1415;
>> project.param.b = 42;

can easily be converted with a command like str=xml_format(project,'off') to
result in:

<project>
..<name>MyProject</name>
..<id>1234</id>
..<param>
....<a>3.1415</a>
....<b>42</b>
..</param>
</project>

Acknowledgements
This submission has inspired the following:
generateXML, Gait Extract Toolbox
MATLAB release MATLAB 6.5 (R13)
Other requirements Tested under Matlab 6.5 (R13) and 7.0.1 (R14SP1). This is XML Toolbox Version 3.1.2.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (57)
15 Sep 2004 Stefan Zimmerman

Just what I've been looking for - easy to use and powerful XML to Matlab converter! - Excellent tool.

22 Oct 2004 Benjamin Davis

Concise and simple to use. Authors didn't fall into the "over do-it" trap of software tool development.

03 Nov 2004 Wilson Cheung

This is much easier to use than Matlab's built xmlread and xmlwrite which require you to be an expert handling XML DOM. It just works like you would expect it to work. The documentation and examples use code is good.

27 May 2005 Ken Doniger

Very simple and effective.
One small complaint: Matlab complains that the P-files are older than the M-files.

11 Jun 2005 lywhus lywhus

The functionality is good. But be aware it is not open source and the author does not intent to make the source available.
Please try to use XML4MAT v2.0 instead.

16 Jun 2005 Concern Reviewer

Good functionality, but the p-file coding limits it usability.

26 Jul 2005 Jose Andrickson  
24 Aug 2005 Concern Matlab User  
04 Oct 2005 Knoll Gernot

That was I'm searching for!
Best free tool what I ever seen

14 Feb 2006 Jaroslaw Tuszynski

Very nice interface, but has many problems:
1) slow - a file parsed by readxml in 13 sec took 8 min for xml_parseany
2) buggy - If you stray from examples than both reading and writing can produce wrong results, like invalid xml code.
3) lack of .m files prevents debugging

15 Mar 2006 A. Belani

A Warning stating that the p code is older than the m code can be received when running some functions from this toolbox. Such warnings can be disabled by using:

warnings_state=warning('off','all');
%Use the desired toolbox functions now.
warning(warnings_state);

31 May 2006 Randy Bithell

It does what it is intended to do. The documentation was the only way I would have known how to get the CONTENT out of the structure. Since only p-files you cannot compile and make an *.exe if that matters to you. You can delete (or move) the m-files if the warning is bothering you, they are obviously just descriptions for when you call the function.

19 Nov 2006 Peter Cotton

Suggest either testing under more versions of Matlab (e.g. 64 bit) or making m-files available for others to do the same.

15 Dec 2006 Jaakko R

Buggy and closed source.

08 Mar 2007 Almon Ing

It did the job for me, and my XML files are pretty complicated.

02 Apr 2007 xia tian

Good

02 May 2007 �ris �lafsdóttir

It is a very effective function, but the drawback is that all the elements in the structure are cells and this cannot be changed. I need a structure of a certain format but have to convert every single element of the structure from cell to array.

17 Aug 2007 K T

If I have:

a =

    b: [3x3 struct]

where:

a.b =
3x3 struct array with fields:
    ATTRIBUTE
    CONTENT

where each of the 3x3 struct array of ATTRIBUTE is:

    k: 1 %(some number)
    j: 1 %(another number)

The xml that is generated is not correct...It only generates xml for the first of the 3x3 array of structs.

Any idea how to get around this issue?

Thanks - Kartik

23 Aug 2007 bill law

It is really a useful tool, but why couldn't i find the file 'xml_toolbox.pdf'?

28 Aug 2007 Maarten V

Very useful tool. One question: I have warnings that the p-files (28/01/2005) are older than the m-files (15/04/2005). Do I need to create new p-files, based on the m-files in the ZIP? Or is it better to do it not?

03 Oct 2007 Jose Andrickson

Soy profor universitario y me gustaria probar las prestaciones de esta herramienta

28 Oct 2007 tuan hoang minh  
06 Nov 2007 Jeremy Wilcox

This XML toolbox was great for my needs:
It allows an easy reading of XML files into matlab and the data handling is efficient.

Thanks!

11 Nov 2007 Dil Djumanov

Hi, if TAG name has minus '-' then it gives the next error.
??? Error using ==> setfield
Error using ==> subsasgn
Invalid field name component.

Error in ==> C:\ProgramFiles\MATLAB71\toolbox\xml_toolbox\xml_parseany.p>xml_parseany at 154

Error in ==> C:\ProgramFiles\MATLAB71\toolbox\xml_toolbox\xml_parseany.p>xml_parseany at 163

Can it be fixed please.
Thanks

11 Jan 2008 Gerald Corzo

Does anyone know how the attributes doesnt read

13 Jan 2008 BAO BING  
18 May 2008 hill how  
02 Aug 2008 lin chen  
02 Aug 2008 manoj loganathan

superb

17 Sep 2008 Gerard Sanromà

good!.. it gives better results than other XML Toolboxes that I have tried for converting .gxl files (graph exchange format) into matlab structures.. Thanks

06 Oct 2008 Guillaume Jacquenot

Good job, but the import of an xml file in MatLab may contain redundant data.

Here is an example, where the MatLab generated structure contain redundant data

<?xml version="1.0" ?>
<polygon id="polygon1" nVertices="3">
<lines>
<segment n="1" x0=" 0.0" x1="966.0" y0=" 86.0" y1="142.0" />
<segment n="2" x0="966.0" x1="1983.0" y0="142.0" y1=" 0.0" />
<segment n="3" x0="1983.0" x1="0.0" y0="0.0" y1="86.0" />
</lines>
<xMax>1983.0</xMax>
<yMax>142.0</yMax>
</polygon>

21 Jan 2009 Kyo Sohma

I was trying to use xml_parseany from a big file, and it doesnt work properly. For example,

<test>
<user id='1'>
<topic id='t1'>
<weight>60</weight>
</topic>
</user>
<user id='2'/>
<user id='3'>
<topic id='t3'>
<weight>20</weight>
</topic>
<topic id='t4'>
<weight>80</weight>
</topic>
</user>
<user id='4'/>
</test>

When this is parsed, user id 2 and 4 dont have topics, but when the struct is created these users have the topics from the last user that had topics.
In this case, user 2 has the same topics that user 1 has, and user 4 has the same topics that 4 has.

21 Jan 2009 Kyo Sohma

correction: user 3 has the same topics that 4 has.

02 Feb 2009 Anna Kelbert

Thanks a lot! Much more efficient than the alternative xml_io_tools (although open source would of course be nice). However, it completely messes up character arrays. If you create an array with a char() function that consists of e.g. four character strings (size 4 x 400), the corresponding XML output is nonsense. On the other hand, writing separate lines as items creates a problem for other software which reads my XML files. There should be an option to concatenate array elements together in the XML file, rather than writing them out as separate 'item' elements.

06 Oct 2009 Rick Crawford

Is this supposed to work with cell arrays? I tried to use it with a cell array and it crashed.

06 Oct 2009 Richard

I'm getting an error message for xml_load when running from command line:
"v = xml_load('Samoa.xml');
??? Attempt to execute SCRIPT xml_load as a function:
H:\mylib\xml\xml_toolbox\xml_load.p"

The file is in the current directory.

23 Dec 2009 Jesse Hopkins

Does not handle XML files that have the same tag name repeated, since this uses the tag name as the field name for matlab structures. This tool appears to ignore all but the last tag of repeated tag names.

I prefer the output format of "XML parsing tools" (FX id 3074), which does handle this, however that one runs painstakingly slow and does not handle comments.

02 Feb 2010 Thomas Schreiter

Nice idea. But no source code provided, which might be OK if the program weren't buggy:
In some cases, saving a matrix containing doubles and nan's leads to the error "NaN's cannot be converted to logicals."

02 Feb 2010 João

Great! It was useful for me many times now.
Schroen, I think you are mistaken. The source code IS included.

03 Feb 2010 Thomas Schreiter

Found one more annoying bug, that's why I downgraded my rating:
it produces invalid XML code in some cases (I have a structure containing some empty fields, the resulting XML file is ~500kB containing invalid XML code)

@Joao: There are M files included, but they contain only comments, no source code.

03 Feb 2010 Thomas Schreiter

Regarding my last post. I found the troublemaker: saving a char with the value 0 leads to a missing closing tag:
Matlab: xml_save('foo.xml', char(0);
foo.XML: <?xml version="1.0"?>
<!-- Written on 03-Feb-2010 10:59:59 using the XML Toolbox for Matlab -->
<root xml_tb_version="3.1" idx="1" type="char" size="1 1">

As you can see, the root tag is not closed.

01 Apr 2010 Neil

Very disappointing closed source software. I do not recommend at all.

21 Jun 2010 Erfan

you have forgot to ignore the white spaces in the XML file dude (in the xml_load function)
doesn't work when there are gaps in the xml file

24 Aug 2010 Thomas Marullo

Great job! This is a wonderful set of tools.

24 Sep 2010 Marion Douglas

As of Matlab 2010b, xml_toolbox is useless since p-file obfuscation has changed in matlab, requiring the original source m-file to make new p-files from. Any plans to release updated p-files?

01 Oct 2010 Marc Molinari

I have changed jobs and a rewrite and update of the XML toolbox will be available as soon as I find time for these... Please check back or add a watch to receive a notification.
If you require urgent specialised changes or integration, please contact me at marc_xml@scieng.co.uk.

28 Oct 2010 Navid Samavati

Totally useful! Exactly what I was looking for! Thanks!

01 Nov 2010 Bhuvan

Hi guys i have doubt is it possible to import back the xml file which download earlier to simmechanics model back to cad model in xml format using this tool bar.

Exactly it is SimMechanics Model to CAD Assembly in xml format & viceversa

pl. help me in this same

02 Feb 2011 Emil

This is a great tool.. Whats the chance in getting an updated p-code?

02 Feb 2011 Emil  
14 Mar 2011 Andreas K.

With Matlab R2007b everything works find, but with R2010b I got the following warning-message...
>Warning: The P-code file strsplit.p was generated prior to MATLAB version 7.5 (R2007b) and will not be
supported in a future release. Use pcode to regenerate strsplit.p using MATLAB R2007b or later.

I can't regenerate those files with R2010b. I don't know why...

05 Apr 2011 Charles Garfinkle

Unable to interpret elements with line breaks between attribute values. Also failed to correctly parse an XML tree composed of nested elements all of the same name and attributes (though the specific values of those attributes differed between elements).

23 Jun 2011 Xiaolong  
23 Jun 2011 Xiaolong

Unable to interprete special characters like > and < in the xml file.

22 Jul 2011 Ad Client

buggy, no way to debug due to closed source.

24 Jan 2012 Joseph Areeda

I'm running R2011b and can't try this because the p code is incompatible.

Are there any other options?

07 Feb 2012 Xiaolong

I am switching to xmltools (also available from MATLAB Central).

This will be the last time I make my project dependent on a closed-source freeware.

Please login to add a comment or rating.
Updates
13 Jan 2004

Removed password for .zip file.
"Please register at the given address."

15 Apr 2005

New version available. Does read XML attributes too.

20 Apr 2005

manual xml_toolbox.pdf now included.

20 Apr 2005

Correction of function names, xml_formatatt to xml_formatany and same for parser.

Tag Activity for this File
Tag Applied By Date/Time
data import Marc Molinari 22 Oct 2008 07:11:16
data export Marc Molinari 22 Oct 2008 07:11:16
xml toolbox Marc Molinari 22 Oct 2008 07:11:16
conversion Marc Molinari 22 Oct 2008 07:11:16
struct Marc Molinari 22 Oct 2008 07:11:16
data type Marc Molinari 22 Oct 2008 07:11:16
matlab Marc Molinari 22 Oct 2008 07:11:16
double Marc Molinari 22 Oct 2008 07:11:17
xml Stephen Lienhard 07 Mar 2009 13:41:00
xml gourish 12 Mar 2009 00:50:10
xml Karsten Stegelmann 30 Jul 2009 08:39:09
xml Christian 02 Feb 2010 08:50:23
xml toolbox Thomas Schreiter 02 Feb 2010 10:12:42
xml Daniel 31 Jan 2011 14:37:01
xml Emil 02 Feb 2011 07:56:08
matlab Manjunath R V 19 Apr 2011 05:52:59
xml T. 22 Jun 2011 11:24:16
xml Bruce 24 Oct 2011 18:40:17
xml Matan Hofree 16 Jan 2012 16:11:00

Contact us at files@mathworks.com