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
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.
I had high hopes after reading the reviews, but... "There should be a single field in the main structure" - why? But worse: for an array of struct the call "isstruct(s.(curfield)" crashes because the return value ia an array!
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...
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.
Thank you thijs for bringing this to my attention. The problem lies not in the regexprep, but in the for loop, however. I have changed the for loop to build a cell array of the multiline sting and execute the regexprep only once. From the MATLAB profiler I obtained that your method is already 38% faster. The regexprep using the cell should be 160% faster than before. I will upload the new function today and hopefully it will be available from Mathworks tomorrow. Thanks again for the suggestion!
For longer arrays of values it takes very long processing!, Use this
nonspace=(whitespace+ [0 whitespace(1:end-1)])~=2; % Only double whitespaces are removed)
str = [str tmp(i,nonspace) sprintf('\n')]