source: trunk/src/@xmltree/xmltree.m @ 1099

Last change on this file since 1099 was 1095, checked in by sommeria, 4 years ago

reading mat files added, +-fixed,OpenDAP improved

File size: 2.6 KB
Line 
1function tree = xmltree(varargin)
2% XMLTREE/XMLTREE Constructor of the XMLTree class
3% FORMAT tree = xmltree(varargin)
4%
5% varargin - XML filename or XML string
6% tree     - XMLTree Object
7%
8%     tree = xmltree;             % creates a minimal XML tree: '<tag/>'
9%     tree = xmltree('foo.xml');  % creates a tree from XML file 'foo.xml'
10%     tree = xmltree('<tag>content</tag>') % creates a tree from string
11%__________________________________________________________________________
12%
13% This is the constructor of the XMLTree class.
14% It creates a tree of an XML 1.0 file (after parsing) that is stored
15% using a Document Object Model (DOM) representation.
16% See http://www.w3.org/TR/REC-xml for details about XML 1.0.
17% See http://www.w3.org/DOM/ for details about DOM platform.
18%__________________________________________________________________________
19% Copyright (C) 2002-2011  http://www.artefact.tk/
20
21% Guillaume Flandin
22% $Id: xmltree.m 4460 2011-09-05 14:52:16Z guillaume $
23
24switch(nargin)
25    case 0
26        tree.tree{1} = struct('type','element',...
27                              'name','tag',...
28                              'attributes',[],...
29                              'contents',[],...
30                              'parent',[],...
31                              'uid',1);
32        tree.filename = '';
33        tree = class(tree,'xmltree');
34    case 1
35        if isa(varargin{1},'xmltree')
36            tree = varargin{1};
37        elseif ischar(varargin{1})
38            % Input argument is an XML string
39            if (~exist(varargin{1},'file') && ...
40                    ~isempty(xml_findstr(varargin{1},'<',1,1)))
41                tree.tree = xml_parser(varargin{1});
42                tree.filename = '';
43                % Input argument is an XML filename
44            else
45                if isempty(regexp(varargin{1},'^http://'))%ordinary file (not OpenDAP)
46                    fid = fopen(varargin{1},'rt');
47                    if (fid == -1)
48                        error(['[XMLTree] Cannot open ' varargin{1}]);
49                    end
50                    xmlstr = fread(fid,'*char')';
51                    %xmlstr = fscanf(fid,'%c');
52                    fclose(fid);
53                else
54                    xmlstr=webread(varargin{1});%OpenDAP case
55                end
56                tree.tree = xml_parser(xmlstr);
57                tree.filename = varargin{1};             
58            end
59            tree = class(tree,'xmltree');
60        else
61            error('[XMLTree] Bad input argument');
62        end
63    otherwise
64        error('[XMLTree] Too many input arguments');
65end
Note: See TracBrowser for help on using the repository browser.