Thanks for the file, however I'm having an issue with empty data fields.
If I have a 100x50 XML data set which I can easily import into Excel. However there are a few fields which are empty. For example at (5,35:40), the XML data is empty.
When I use the xml2struct and then try and create a cell array in the same format (100x50) the data in row 5 between 40:50, shifts to the 35:45 position and I'm left with 5 empty spaces from 45:50 and as such the data is misaligned.
Any idea on how to deal with empty fields in order to maintain their position in the original file?
Thanks!
Comment only
22 Apr 2013
xml2struct
Convert an xml file into a MATLAB structure for easy access to the data.
i was just wondering if someone could just confirm what i am doing is correct. when i want to convert xml into a matlab array, i type:
data=xml2struct('name of the file i want to convert'); ? is that all?
Comment only
12 Apr 2013
xml2struct
Convert an xml file into a MATLAB structure for easy access to the data.
We are encountering the same issue reported by Raoul Herzog: Undefined function or method 'toCharArray' for input arguments of type 'double'. Is there a fix for this?
Comment only
10 Dec 2012
xml2struct
Convert an xml file into a MATLAB structure for easy access to the data.
For the comment bug, @Sirius3, I changed the following code block from:
if (~strcmp(name,'#text') && ~strcmp(name,'#comment') && ~strcmp(name,'#cdata_dash_section'))
%XML allows the same elements to be defined multiple times,
%put each in a different cell
if (isfield(children,name))
if (~iscell(children.(name)))
%put existsing element into cell format
children.(name) = {children.(name)};
end
index = length(children.(name))+1;
%add new element
children.(name){index} = childs;
if(~isempty(fieldnames(text)))
children.(name){index} = text;
end
if(~isempty(attr))
children.(name){index}.('Attributes') = attr;
end
else
%add previously unknown (new) element to the structure
children.(name) = childs;
if(~isempty(text) && ~isempty(fieldnames(text)))
children.(name) = text;
end
if(~isempty(attr))
children.(name).('Attributes') = attr;
end
end
else
to
if (~strcmp(name,'#text') && ~strcmp(name,'#comment') && ~strcmp(name,'#cdata_dash_section'))
%XML allows the same elements to be defined multiple times,
%put each in a different cell
if (isfield(children,name))
if (~iscell(children.(name)))
%put existsing element into cell format
children.(name) = {children.(name)};
end
index = length(children.(name))+1;
%add new element
children.(name){index} = childs;
textFieldNames = fieldnames(text);
for t = 1:length(textFieldNames)
textFieldName = textFieldNames{t};
children.(name){index}.(textFieldName) = text.(textFieldName);
end
if(~isempty(attr))
children.(name){index}.('Attributes') = attr;
end
else
%add previously unknown (new) element to the structure
children.(name) = childs;
if(~isempty(text) && ~isempty(fieldnames(text)))
textFieldNames = fieldnames(text);
numTextFieldNames = length( textFieldNames );
for i = 1:numTextFieldNames
thisFieldName = textFieldNames{i};
children.(name).(thisFieldName) = text.(thisFieldName);
end
end
if(~isempty(attr))
children.(name).('Attributes') = attr;
end
end
else
Now, the children.(name) properties are not blown away when a comment is parsed.
Comment only