MatrixBerryCore
xmlload.m
Go to the documentation of this file.
1 function [SData,SMetaData] = xmlload(fileName)
2 import mxberry.xml.*;
3 import mxberry.core.throwerror;
4 [~,~,extStr]=fileparts(fileName);
5 if isempty(extStr)
6  fileName = strcat(fileName, '.xml');
7 elseif ~isequal(lower(extStr),'.xml')
8  mxberry.core.throwerror('wrongInput',...
9  'fileName should point to an xml file');
10 end
11 %
12 %-----------------------------------------------
13 % check existence of file
14 if ~mxberry.io.isfile(fileName)
15  throwerror('wrongInput:fileDoesntExist','Could not find %s',fileName);
16 end
17 %-----------------------------------------------
18 %Use java parser as a temporary tool to check that xml is well-formed
19 try
20  %calling built-in xml read function
21  xmlread(fileName);
22 catch meObj
23  newMeObj=throwerror('wrongInput:notWellFormedFile',...
24  'xml is not well formed');
25  newMeObj=newMeObj.addCause(meObj);
26  throw(newMeObj);
27 end
28 %-----------------------------------------------
29 [fid,errMsgStr] = fopen(fileName, 'r');
30 if fid==-1
31  throwerror('wrongInput:couldNotOpen',...
32  'Could not open file %s for reading, reason: %s',fileName,...
33  errMsgStr);
34 end
35 
36 % parse file content into blocks
37 contentStr = fread(fid,'*char').'; % read in whole file
38 fclose( fid );
39 
40 if numel(contentStr)<3
41  throwerror('wrongInput:notValidFile',...
42  '%s does not seem to be a valid xml file.',...
43  fileName);
44 end
45 %-----------------------------------------------
46 % parse content, identify blocks
47 [SData,SMetaData] = mxberry.xml.xmlparse(contentStr);
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 xmlload(in fileName)
XMLLOAD loads XML file and converts it into Matlab structure or variable.
function isfile(in fileName, in isJavaBased)
ISFILE returns true if a specified name corresponds to an existing file.
function xmlparse(in inpXmlString, in attSwitch, in SData, in level)
XMLPARSE parses XML string str and returns matlab variable/structure. This is a non-validating parser...