Changeset 820


Ignore:
Timestamp:
Oct 8, 2014, 8:51:12 PM (9 years ago)
Author:
sommeria
Message:

xmltree_updated

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  
    2020%
    2121%   See also STRFIND, FINDSTR
     22%_______________________________________________________________________
     23% Copyright (C) 2002-2008  http://www.artefact.tk/
    2224
    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 $
    2727
    28 error(sprintf('Missing MEX-file: %s', mfilename));
     28%error(sprintf('Missing MEX-file: %s', mfilename));
     29
     30persistent runonce
     31if 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;
     35end
     36
     37% k = regexp(s(i:end),p,'once') + i - 1;
     38if nargin < 3, i = 1;   end
     39if nargin < 4, n = Inf; end
     40j = strfind(s,p);
     41k = j(j>=i);
     42if ~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)
     1function tree = xml_parser(xmlstr)
    22% XML (eXtensible Markup Language) Processor
    3 % FORMAT tree = xml_parser(filename)
    4 %
    5 % filename - XML file to parse
    6 % tree     - tree structure corresponding to the XML file
     3% FORMAT tree = xml_parser(xmlstr)
     4%
     5% xmlstr  - XML string to parse
     6% tree    - tree structure corresponding to the XML file
    77%_______________________________________________________________________
    88%
     
    1010% written in Matlab. It aims to be fully conforming. It is currently not
    1111% a validating XML processor.
    12 % (based on a Javascript parser available at http://www.jeremie.com)
    1312%
    1413% A description of the tree structure provided in output is detailed in
    1514% the header of this m-file.
    1615%_______________________________________________________________________
    17 % @(#)xml_parser.m               Guillaume Flandin           2002/04/04
     16% @(#)xml_parser.m              Guillaume Flandin            2002/04/04
    1817
    1918% XML Processor for MATLAB (The Mathworks, Inc.).
    20 % Copyright (C) 2002  Guillaume Flandin
     19% Copyright (C) 2002-2003 Guillaume Flandin <Guillaume@artefact.tk>
    2120%
    2221% This program is free software; you can redistribute it and/or
     
    3534%-----------------------------------------------------------------------
    3635
    37 % Please feel free to email the author any comment/suggestion/bug report
    38 % to improve this XML processor in Matlab.
    39 % Email: Guillaume.Flandin@sophia.inria.fr
     36% 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>
    4039% 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/>
    4345
    4446% A mex-file xml_findstr.c is also required, to encompass some
     
    9294
    9395% TODO/BUG/FEATURES:
    94 %  - [compile] only a warning if TagStart is empty
     96%  - [compile] only a warning if TagStart is empty ?
    9597%  - [attribution] should look for " and ' rather than only "
    9698%  - [main] with normalize as a preprocessing, CDATA are modified
    9799%  - [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
    99101%  - [tag_element] erode should replace normalize here
    100102%  - remove globals? uppercase globals  rather persistent (clear mfile)?
    101 %  - xml_findst is in fact xml_strfind according to Mathworks vocabulary
    102 %  - problem with entity (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? (&eacute;)
    103105%-----------------------------------------------------------------------
    104106
     
    108110%- Check input arguments
    109111error(nargchk(1,1,nargin));
    110 if isempty(filename)
    111         error('Not enough parameters.')
    112 elseif ~isstr(filename) | sum(size(filename)>1)>1
    113         error('Input must be a string filename.')
     112if isempty(xmlstr)
     113        error('[XML] Not enough parameters.')
     114elseif ~isstr(xmlstr) | sum(size(xmlstr)>1)>1
     115        error('[XML] Input must be a string.')
    114116end
    115 
    116 %- Read the entire XML file
    117 fid = fopen(filename,'rt');
    118 if (fid==-1)
    119         error(sprintf('Cannot open %s for reading.',filename))
    120 end
    121 xmlstring = fscanf(fid,'%c');
    122 fclose(fid);
    123117
    124118%- Initialize number of tags (<=> uid)
     
    126120
    127121%- Remove prolog and white space characters from the XML string
    128 xmlstring = normalize(prolog(xmlstring));
     122xmlstring = normalize(prolog(xmlstr));
    129123
    130124%- Initialize the XML tree
     
    157151                TagStart = xml_findstr(xmlstring,'<',frag.str,1);
    158152                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;
    164157                        xtree{Xparse_count}.value = erode(entity(xmlstring(frag.str:end)));
    165158                        xtree{Xparse_count}.parent = frag.parent;
    166159                        xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
    167                         %frag.str = '';
     160                        frag.str = '';
    168161                elseif TagStart > frag.str
    169162                        if strcmp(xmlstring(frag.str:TagStart-1),' ')
Note: See TracChangeset for help on using the changeset viewer.