MatrixBerryCore
xmlsave.m
Go to the documentation of this file.
1 function xmlsave( fileName, SData, varargin)
2 import mxberry.xml.*;
3 import mxberry.core.throwerror;
4 import mxberry.core.check.checkgen;
5 import mxberry.core.check.lib.isstring;
6 %
7 checkgen(fileName,'isstring(x)');
8 if nargin<2
9  throwerror('wrongInput','SData is an obligatory input argument');
10 end
11 %
12 [reg,~,isTsInserted]=mxberry.core.parseparext(varargin,...
13  {'insertTimestamp';true;'islogical(x)&isscalar(x)'},[0 2],...
14  'regDefList',{'on',struct()},...
15  'regCheckList',...
16  {@(x)isstring(x)&&ismember(x,{'on','off','forceon'}),...
17  @(x)isstruct(x)&&isscalar(x)&&all(structfun(@ischar,x))});
18 %
19 attSwitch=reg{1};
20 SMetaData=reg{2};
21 %
22 if isempty(strfind(lower(fileName),'.xml'))
23  fileName = strcat(fileName, '.xml');
24 end
25 %
26 [fid,errMsg] = fopen(fileName, 'w');
27 if fid==-1
28  throwerror('wrongInput:badFile',...
29  'Failed to open file %s for writing: %s',fileName,errMsg);
30 end
31 %
32 fprintf(fid, '<?xml version="1.0"?>\n');
33 %
34 if isTsInserted
35  fprintf(fid, sprintf('<!-- written on %s -->\n', datestr(now)));
36 end
37 %
38 try
39  fprintf(fid, '%s', xmlformat(SData, attSwitch,'root',0,SMetaData));
40  fclose(fid);
41 catch meObj
42  fclose(fid);
43  rethrow(meObj);
44 end
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function checkgen(in x, in typeSpec, in varargin)
CHECKGEN checks a generic condition provided by typeSpec string in the following format: &#39;isnumeric(x...
function xmlformat(in SData, in attSwitch, in name, in level, in SMetaData)
XMLFORMAT formats the variable V into a name-based tag XML string xstr.
function isstring(in inpArray)
function xmlsave(in fileName, in SData, in varargin)
XMLSAVE saves structure or variable(s) to a file using XML format.
function ismember(in leftVec, in rightVec, in varargin)
ISMEMBER - ismember implementation for arrays of any type.