Changeset 925 for trunk/src/@xmltree/xmltree.m
- Timestamp:
- Feb 17, 2016, 12:52:48 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/@xmltree/xmltree.m
r821 r925 9 9 % tree = xmltree('foo.xml'); % creates a tree from XML file 'foo.xml' 10 10 % tree = xmltree('<tag>content</tag>') % creates a tree from string 11 %_______________________________________________________________________ 11 %__________________________________________________________________________ 12 12 % 13 13 % This is the constructor of the XMLTree class. … … 16 16 % See http://www.w3.org/TR/REC-xml for details about XML 1.0. 17 17 % See http://www.w3.org/DOM/ for details about DOM platform. 18 %_______________________________________________________________________ 19 % @(#)xmltree.m Guillaume Flandin 02/03/27 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 $ 20 23 21 24 switch(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'); 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 fid = fopen(varargin{1},'rt'); 46 if (fid == -1) 47 error(['[XMLTree] Cannot open ' varargin{1}]); 48 end 49 xmlstr = fread(fid,'*char')'; 50 %xmlstr = fscanf(fid,'%c'); 51 fclose(fid); 52 tree.tree = xml_parser(xmlstr); 53 tree.filename = varargin{1}; 54 end 55 tree = class(tree,'xmltree'); 56 else 57 error('[XMLTree] Bad input argument'); 58 end 59 otherwise 60 error('[XMLTree] Too many input arguments'); 57 61 end
Note: See TracChangeset
for help on using the changeset viewer.