Rank: 487723 based on 0 downloads (last 30 days) and 0 file submitted
photo

Neill Weiss

E-mail

Personal Profile:

 

Watch this Author's files

 

Comments and Ratings by Neill Weiss
Updated File Comments Rating
10 Dec 2012 xml2struct Convert an xml file into a MATLAB structure for easy access to the data. Author: Wouter Falkena

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.

Contact us