⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 struct2xml.m

📁 This code can parse any image in matlab. Very elaborate code
💻 M
字号:
function xml = struct2xml(v)
%
% Transforms a struct or struct array into an XML string
%
% v = struct variable containing fields of type char or numeric
%

xml = [];

% New line character:
nl = char(13);
% Use nl = '' to remove new line characters.

names = fieldnames(v);
for n = 1:length(names)
    a = getfield(v, names{n});

    if isstruct(a)
        % If it is a struct, recursive call
        Nitems = length(a);
        % loop if it is a struct array
        for i = 1:Nitems
            xml = [xml '<' names{n} '>' nl struct2xml(a(i)) '</' names{n} '>' nl];
        end
    else
        % write field contents:
        if iscell(a); Nitems = length(a); else Nitems=1; a={a};end
        
        for i = 1:Nitems
            xml = [xml '<' names{n} '>' nl];
            if ischar(a{i})
                xml = [xml a{i} nl];
            else
                xml = [xml num2str(a{i}') nl];
            end
            xml = [xml '</' names{n} '>' nl];
        end
    end
end


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -