- Timestamp:
- Oct 8, 2014, 8:51:12 PM (10 years ago)
- Location:
- trunk/src/@xmltree/private
- Files:
-
- 2 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/@xmltree/private/xml_findstr.m
r723 r820 20 20 % 21 21 % See also STRFIND, FINDSTR 22 %_______________________________________________________________________ 23 % Copyright (C) 2002-2008 http://www.artefact.tk/ 22 24 23 % Guillaume Flandin 24 % Copyright 2002 INRIA Sophia Antipolis 25 % $Revision: 1.0 $ $Date: 2002/04/10 22:50:32 $ 26 % Implemented in a MATLAB mex file. 25 % Guillaume Flandin <guillaume@artefact.tk> 26 % $Id: xml_findstr.m 2271 2008-09-30 21:19:47Z guillaume $ 27 27 28 error(sprintf('Missing MEX-file: %s', mfilename)); 28 %error(sprintf('Missing MEX-file: %s', mfilename)); 29 30 persistent runonce 31 if isempty(runonce) 32 warning(sprintf(['xml_findstr is not compiled for your platform.\n'... 33 'This will result in a slowdown of the XML parsing.'])); 34 runonce = 1; 35 end 36 37 % k = regexp(s(i:end),p,'once') + i - 1; 38 if nargin < 3, i = 1; end 39 if nargin < 4, n = Inf; end 40 j = strfind(s,p); 41 k = j(j>=i); 42 if ~isempty(k), k = k(1:min(n,length(k))); end -
trunk/src/@xmltree/private/xml_parser.m
r723 r820 1 function tree = xml_parser( filename)1 function tree = xml_parser(xmlstr) 2 2 % XML (eXtensible Markup Language) Processor 3 % FORMAT tree = xml_parser( filename)4 % 5 % filename - XML fileto parse6 % tree 3 % FORMAT tree = xml_parser(xmlstr) 4 % 5 % xmlstr - XML string to parse 6 % tree - tree structure corresponding to the XML file 7 7 %_______________________________________________________________________ 8 8 % … … 10 10 % written in Matlab. It aims to be fully conforming. It is currently not 11 11 % a validating XML processor. 12 % (based on a Javascript parser available at http://www.jeremie.com)13 12 % 14 13 % A description of the tree structure provided in output is detailed in 15 14 % the header of this m-file. 16 15 %_______________________________________________________________________ 17 % @(#)xml_parser.m Guillaume Flandin2002/04/0416 % @(#)xml_parser.m Guillaume Flandin 2002/04/04 18 17 19 18 % XML Processor for MATLAB (The Mathworks, Inc.). 20 % Copyright (C) 2002 Guillaume Flandin19 % Copyright (C) 2002-2003 Guillaume Flandin <Guillaume@artefact.tk> 21 20 % 22 21 % This program is free software; you can redistribute it and/or … … 35 34 %----------------------------------------------------------------------- 36 35 37 % Please feel free to email the author any comment/suggestion/bug report38 % to improve this XML processor in Matlab.39 % Email: Guillaume.Flandin@sophia.inria.fr36 % Suggestions for improvement and fixes are always welcome, although no 37 % guarantee is made whether and when they will be implemented. 38 % Send requests to <Guillaume@artefact.tk> 40 39 % Check also the latest developments on the following webpage: 41 % http://www-sop.inria.fr/epidaure/personnel/flandin/xml/ 42 %----------------------------------------------------------------------- 40 % <http://www.artefact.tk/software/matlab/xml/> 41 %----------------------------------------------------------------------- 42 43 % The implementation of this XML parser is much inspired from a 44 % Javascript parser available at <http://www.jeremie.com/> 43 45 44 46 % A mex-file xml_findstr.c is also required, to encompass some … … 92 94 93 95 % TODO/BUG/FEATURES: 94 % - [compile] only a warning if TagStart is empty 96 % - [compile] only a warning if TagStart is empty ? 95 97 % - [attribution] should look for " and ' rather than only " 96 98 % - [main] with normalize as a preprocessing, CDATA are modified 97 99 % - [prolog] look for a DOCTYPE in the whole string even if it occurs 98 % only in a far CDATA tag (for example)...100 % only in a far CDATA tag, bug even if the doctype is inside a comment 99 101 % - [tag_element] erode should replace normalize here 100 102 % - remove globals? uppercase globals rather persistent (clear mfile)? 101 % - xml_findst is in factxml_strfind according to Mathworks vocabulary102 % - problem with entit y (don't know if the bug is here or in save fct.)103 % - xml_findstr is indeed xml_strfind according to Mathworks vocabulary 104 % - problem with entities: do we need to convert them here? (é) 103 105 %----------------------------------------------------------------------- 104 106 … … 108 110 %- Check input arguments 109 111 error(nargchk(1,1,nargin)); 110 if isempty( filename)111 error(' Not enough parameters.')112 elseif ~isstr( filename) | sum(size(filename)>1)>1113 error(' Input must be a string filename.')112 if isempty(xmlstr) 113 error('[XML] Not enough parameters.') 114 elseif ~isstr(xmlstr) | sum(size(xmlstr)>1)>1 115 error('[XML] Input must be a string.') 114 116 end 115 116 %- Read the entire XML file117 fid = fopen(filename,'rt');118 if (fid==-1)119 error(sprintf('Cannot open %s for reading.',filename))120 end121 xmlstring = fscanf(fid,'%c');122 fclose(fid);123 117 124 118 %- Initialize number of tags (<=> uid) … … 126 120 127 121 %- Remove prolog and white space characters from the XML string 128 xmlstring = normalize(prolog(xmlstr ing));122 xmlstring = normalize(prolog(xmlstr)); 129 123 130 124 %- Initialize the XML tree … … 157 151 TagStart = xml_findstr(xmlstring,'<',frag.str,1); 158 152 if isempty(TagStart) 159 %- Character data (should be an error) 160 warning('[XML] Unknown data at the end of the XML file.'); 161 fprintf('Please send me your XML file at gflandin@sophia.inria.fr\n'); 162 %thisary = length(frag.ary) + 1; 163 xtree{Xparse_count+1} = chardata; 153 %- Character data 154 error(sprintf(['[XML] Unknown data at the end of the XML file.\n' ... 155 ' Please send me your XML file at Guillaume@artefact.tk'])); 156 xtree{Xparse_count} = chardata; 164 157 xtree{Xparse_count}.value = erode(entity(xmlstring(frag.str:end))); 165 158 xtree{Xparse_count}.parent = frag.parent; 166 159 xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count]; 167 %frag.str = '';160 frag.str = ''; 168 161 elseif TagStart > frag.str 169 162 if strcmp(xmlstring(frag.str:TagStart-1),' ')
Note: See TracChangeset
for help on using the changeset viewer.