writexml.m

来自「This code can parse any image in matlab.」· M 代码 · 共 56 行

M
56
字号
function writeXML(filename, v)
%
% Transforms a struct or struct array into an XML file
%
% filename = name of the XML file
% v = struct variable containing fields of type char or numeric
%
% xml.tag.object ='foo'
% xml.tag.property(1) = {'foobar1'}
% xml.tag.property(2) = {'foobar2'}
% xml.tag.childrens(1).name ='Pedro'
% xml.tag.childrens(1).age ='12'
% xml.tag.childrens(2).name ='Juan'
% xml.tag.childrens(2).age ='15'
%
% writeXML(filename, xml) will generate a .xml file that contains:
%
% <tag>
%   <object>
%       foo
%   </object>
%   <property>
%       foobar1
%   </property>
%   <property>
%       foobar2
%   </property>
%   <childrens>
%      <name>
%        Pedro
%      </name>
%      <age>
%        12
%      </age>
%   </childrens>
%   <childrens>
%      <name>
%        Juan
%      </name>
%      <age>
%        15
%      </age>
%   </childrens>
% </tag>
%

xml = struct2xml(v);

% Open file
fid = fopen(filename,'w');
fprintf(fid, xml);
% Close file
fclose(fid);


⌨️ 快捷键说明

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