Home > atmlab > arts > xml > xmlLoad.m

xmlLoad

PURPOSE ^

Loads data from an xml file.

SYNOPSIS ^

function result = xmlLoad(filename)

DESCRIPTION ^

 Loads data from an xml file.

    The data type is determined from the file and *result* adapted
    accordingly.

    On error, the execution is stopped and an error message is printed.

 FORMAT   result = xmlLoad(filename)

 OUT   result     Data read from file
 IN    filename   XML filename

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

xmlLoad.m

SOURCE CODE ^

0001 % Loads data from an xml file.
0002 %
0003 %    The data type is determined from the file and *result* adapted
0004 %    accordingly.
0005 %
0006 %    On error, the execution is stopped and an error message is printed.
0007 %
0008 % FORMAT   result = xmlLoad(filename)
0009 %
0010 % OUT   result     Data read from file
0011 % IN    filename   XML filename
0012  
0013 % 2002-09-25   Created by Oliver Lemke.
0014 
0015 function result = xmlLoad(filename)
0016 
0017 uncompressed_filename='';
0018 if strcmp( filename(length(filename)-2:end), '.gz')
0019   workarea = atmlab( 'WORK_AREA' );
0020   uncompressed_filename = tempname(workarea);
0021   cmd = [ 'gunzip -cd ' filename ' > ' uncompressed_filename ];
0022   st = system (cmd);
0023   if st
0024     delete (uncompressed_filename);
0025     error ('Failed to uncompress XML file');
0026   end
0027   filename = uncompressed_filename;
0028 end
0029 
0030 fid = fopen (filename,'rt');
0031 cobj = onCleanup(@()fclose(fid));
0032 
0033 if fid == -1
0034   if ~strcmp (uncompressed_filename, '')
0035     delete (uncompressed_filename);
0036   end
0037   error ('Cannot open file %s', filename);
0038 end
0039 
0040 %=== Validate XML file header
0041 c = fgets (fid, 1);
0042 s = c;
0043 while ~feof (fid) && c ~= '>'
0044   c = fgets (fid, 1);
0045   s = [s c];
0046 end
0047 
0048 s = s(s ~= ' ');
0049 
0050 if ~strcmp (s, '<?xmlversion="1.0"?>')
0051   if ~strcmp (uncompressed_filename, '')
0052     delete (uncompressed_filename);
0053   end
0054   error ('Invalid xml header');
0055 end
0056 
0057 %=== Parsing data tag
0058 result = xmlReadTag(fid, filename, '', '', 0, 0);
0059 
0060 if ~strcmp (uncompressed_filename, '')
0061   delete (uncompressed_filename);
0062 end
0063

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005