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

Last change on this file since 821 was 821, checked in by sommeria, 10 years ago

xmltree_updated

File size: 1.9 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% @(#)xmltree.m                 Guillaume Flandin              02/03/27
20
21switch(nargin)
22        case 0
23                tree.tree{1} = struct('type','element',...
24                                      'name','tag',...
25                                                      'attributes',[],...
26                                                      'contents',[],...
27                                                          'parent',[],...
28                                                      'uid',1);
29                tree.filename = '';
30                tree = class(tree,'xmltree');
31        case 1
32                if isa(varargin{1},'xmltree')
33                        tree = varargin{1};
34                elseif ischar(varargin{1})
35                        % Input argument is an XML string
36                        if (exist(varargin{1}) ~= 2 & ...
37                                ~isempty(xml_findstr(varargin{1},'<',1,1)))
38                                tree.tree = xml_parser(varargin{1});
39                                tree.filename = '';
40                        % Input argument is an XML filename
41                        else
42                                fid = fopen(varargin{1},'rt');
43                                if (fid == -1)
44                                        error(['[XMLTree] Cannot open ' varargin{1}]);
45                                end
46                                xmlstr = fscanf(fid,'%c');
47                                fclose(fid);
48                                tree.tree = xml_parser(xmlstr);
49                                tree.filename = varargin{1};
50                        end
51                        tree = class(tree,'xmltree');
52                else
53                        error('[XMLTree] Bad input argument');
54                end
55        otherwise
56                error('[XMLTree] Too many input arguments');
57end
Note: See TracBrowser for help on using the repository browser.