Rank: 290 based on 349 downloads (last 30 days) and 2 files submitted
photo

Wouter Falkena

E-mail
Company/University
Delft University of Technology
Lat/Long
51.99001312255859, 4.375315189361572

Personal Profile:

 

Watch this Author's files

 

Files Posted by Wouter Falkena View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
15 May 2012 xml2struct Convert an xml file into a MATLAB structure for easy access to the data. Author: Wouter Falkena xml, xml2struct, struct 275 32
  • 4.8125
4.8 | 33 ratings
02 Jan 2012 struct2xml Convert a MATLAB structure into a XML file. Author: Wouter Falkena struct2xml, struct, xml 74 17
  • 4.28571
4.3 | 14 ratings
Comments and Ratings by Wouter Falkena View all
Updated File Comments Rating
04 Jan 2012 struct2xml Convert a MATLAB structure into a XML file. Author: Wouter Falkena

Hi Harald,

The reason why the function requires a single field in the main structure is that a properly formatted XML document has a single root element (http://www.w3schools.com/xml/xml_dtd.asp). The only exception to that rule is a more elaborate XML preamble, which is currently not supported by the function.

For the second point, XML files usually have multiple elements with the same name. In order to convert this into a MATLAB structure, an array may be used. This means that isstruct(s.(curfield)) indeed may not work, but in that case
if iscell(s.(curfield))
min(cellfun(@(a) isstruct(a),s.curfield))
end
will tell you if all cells in the array are structures.

I hope this clarifies how to use the function a bit. If you have any more questions feel free to contact me.

Regards,
Wouter

02 Jan 2012 struct2xml Convert a MATLAB structure into a XML file. Author: Wouter Falkena

Hi Emil,

The function indeed replaces the characters -:. with _ (also see the function help). It should be possible to rewrite the function to replace : with something unique like _colon_ and let struct2xml replace this with :. Let me know if you still need this functionality. The structure names do get longer in that way...

Regards,
Wouter

19 Sep 2011 struct2xml Convert a MATLAB structure into a XML file. Author: Wouter Falkena

Thank you Herbert for finding and successfully eradicating this bug. I have uploaded the fixed file to the MATLAB Central.

04 Jul 2011 xml2struct Convert an xml file into a MATLAB structure for easy access to the data. Author: Wouter Falkena

Thank you for this suggestion Mr. Wanner. I have updated the file and it is currently under review by the MATLAB Central. It will appear here shortly.

13 Apr 2011 struct2xml Convert a MATLAB structure into a XML file. Author: Wouter Falkena

You are correct. However, isspace does not operate on cells. In the latest update I removed the for-loop all together and use isspace on the multi-line string. This is the fastest approach yet. Again, thank you for your support.

Comments and Ratings on Wouter Falkena's Files View all
Updated File Comment by Comments Rating
05 Dec 2014 xml2struct Convert an xml file into a MATLAB structure for easy access to the data. Author: Wouter Falkena William Murphy

Downloaded this file this evening to process some XML data. worked just fine.

03 Dec 2014 xml2struct Convert an xml file into a MATLAB structure for easy access to the data. Author: Wouter Falkena Bernhard

Sorry, pasted the wrong line.
Here is line 154 that fixes the problem for me:

text.(textflag) = char(getTextContent(theNode));

03 Dec 2014 xml2struct Convert an xml file into a MATLAB structure for easy access to the data. Author: Wouter Falkena Bernhard

Great stuff.

Regarding that "Undefined function 'toCharArray' for input arguments of type 'double'." Error:

For me it worked to change line 154 into
text.(textflag) = char(getData(theNode))';
as it has been in an earlier version of xml2struct (mentioned in the comments in the code in line 153)

06 Nov 2014 xml2struct Convert an xml file into a MATLAB structure for easy access to the data. Author: Wouter Falkena Chris FUNG

09 Oct 2014 xml2struct Convert an xml file into a MATLAB structure for easy access to the data. Author: Wouter Falkena Sebastien Roy

Great time saver when compared to using xmlread directly. However, there is a bug with child nodes when a text is present. The child node content will be set to the text and all other content of the child will be lost. A comment, being processed as text, will cause the same issue. Attempting to read this xml will not provide the expected result:

<?xml version="1.0" encoding="UTF-8"?>

<root>
<!-- Should be a benign comment -->
<mystuff>Valuable data</mystuff>
</root>

Contact us