1 function resXmlString =
xmlformat(SData,attSwitch,name,level,SMetaData)
5 NL_SYMBOL = sprintf(
'\n');
6 SPRINTF_SPEC_NUMERIC=
'%0.16g ';
10 throwerror(
'wrongInput',
'SData is an obligatory input argument');
15 attSwitch=lower(attSwitch);
17 isForceAtt=strcmpi(attSwitch,
'forceon');
18 isAtt=isForceAtt||strcmpi(attSwitch,
'on');
20 if nargin<3 || isempty(name)
24 if nargin<4 || isempty(level)
34 paddingStr=
char.empty(1,0);
36 paddingStr(1,level)=
' ';
37 paddingStr(:)=sprintf(
'\t');
40 SAttributes.name = name;
44 fieldNameList=fieldnames(SMetaData);
46 attribList=strcat({
' '},fieldNameList,
'=',...
47 cellfun(@(x)sprintf(
'"%s"',SMetaData.(x)),fieldNameList,...
48 'UniformOutput',
false));
49 attributesStr=[attribList{:}];
52 attributesStr = [attributesStr,
' type="',SAttributes.type,
'" '];
56 attributesStr=[attributesStr,...
57 'size="',SAttributes.size,
'"'];
60 resXmlString = [resXmlString,
'<',name,attributesStr];
64 resXmlString = [resXmlString,
'/> ',NL_SYMBOL];
70 switch lower(SAttributes.type)
72 case {
'char',
'string'}
75 resXmlString = [resXmlString,'>
',contentStr,'</
',name,'>
',... 80 resXmlString = [resXmlString,'>
',NL_SYMBOL]; 81 fieldNameList = fieldnames(SData); 82 nFields=numel(fieldNameList); 86 for iField = 1:nFields 88 fieldName=fieldNameList{iField}; 89 SChild.content = SData(iElem).(fieldName); 90 SChild.attributes = ''; 93 SChild.att.idx = iElem; 94 SChild.att.type = getClass(SChild.content); 96 SChild.attributes = [' type=
"',SChild.att.type,'" ']; 98 SChild.attributes = [' idx=
"',... 99 sprintf('%d',iElem),'"',SChild.attributes]; 101 if getIsNotRow(SChild.content) 102 sizeVec=size(SChild.content); 103 SChild.att.size = deblank(sprintf('%d
',sizeVec)); 104 SChild.attributes=[SChild.attributes,... 105 'size=
"',SChild.att.size,'"']; 109 resXmlString = [resXmlString,paddingStr,'<
',... 110 fieldName,SChild.attributes]; 112 str =xmlformat(SChild.content,attSwitch,fieldName,... 115 resXmlString = [resXmlString,str]; 118 resXmlString = [resXmlString,paddingStr(1:end-1),'</
',... 122 resXmlString = [resXmlString,'>
',NL_SYMBOL]; 125 SChild.content = SData{iElem}; 127 resXmlString = [resXmlString,paddingStr,'<item
']; %#ok<*AGROW> 129 SChild.att.idx = iElem; 130 SChild.att.type = getClass(SChild.content); 131 SChild.attributes = [' type=
"',SChild.att.type,'" ']; 133 if getIsNotRow(SChild.content) 134 SChild.att.size = mynum2str(size(SChild.content)); 135 SChild.attributes=[SChild.attributes,'size=
"',... 136 SChild.att.size,'"']; 138 resXmlString = [resXmlString,SChild.attributes]; 141 resXmlString = [resXmlString,xmlformat(SChild.content,... 142 attSwitch,'item
',nextLevel)]; 144 resXmlString = [resXmlString,paddingStr(1:end-1),... 145 '</
',name,'>
',NL_SYMBOL]; 148 contentStr = sprintf(SPRINTF_SPEC_NUMERIC,SData(:)); 150 newObj=mxberry.core.throwerror('wrongInput:wrongType
',... 151 'type %s is not supported
',SAttributes.type); 152 newObj=addCause(newObj,meObj); 155 resXmlString = [resXmlString,'>
',contentStr(1:end-1),... 156 '</
',name,'>
',NL_SYMBOL]; 158 function className = getClass(inpVal) 160 if ~isreal(inpVal)||issparse(inpVal) 161 mxberry.core.throwerror('wrongInput:wrongType
',... 162 'complex or sparse values are not supported
'); 166 className=class(inpVal); 168 function isPositive=getIsNotRow(inpArray) 169 isPositive=isForceAtt||isempty(inpArray)||~isrow(inpArray); 171 function s=mynum2str(aVec) 172 s=sprintf('%d
',aVec); 177 function content=charFuncSubstitute(content) 178 content=strrep(content,'&
','&
'); 179 content=strrep(content,'<
','<
'); 180 content=strrep(content,'>
','>
'); 181 content=strrep(content,'''',
''');
182 content=strrep(content,
'"',
'"');
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 mynum2str(in aVec)
function getIsNotRow(in inpArray)
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 getClass(in inpVal)
function charFuncSubstitute(in content)