Index: trunk/src/@xmltree/private/xml_findstr.c
===================================================================
--- trunk/src/@xmltree/private/xml_findstr.c	(revision 820)
+++ trunk/src/@xmltree/private/xml_findstr.c	(revision 925)
@@ -2,18 +2,25 @@
 
 /*
-    Differences with matlab built-in findstr:
+ * $Id: xml_findstr.c 6480 2015-06-13 01:08:30Z guillaume $
+ * Guillaume Flandin <guillaume@artefact.tk>
+ */
+
+/*
+    Differences with built-in findstr:
         - allows to search only the n first occurences of a pattern
         - allows to search only in a substring (given an index of the beginning)
    
-    Matlab hack:
+    MATLAB hack:
         - doesn't use mxGetString to prevent a copy of the string.
-        - assumes Matlab stores strings as unsigned short (Unicode 16 bits)
+        - assumes MATLAB stores strings as unsigned short (Unicode 16 bits)
           matrix.h: typedef uint16_T mxChar;
-          (that's the case for Matlab 5.* and 6.* but Matlab 4.* stores strings
-           as double)
+          (that's the case for MATLAB 5.*, 6.* and 7.* but MATLAB 4.* stores
+           strings as double and GNU Octave as char, see src/mxarray.h)
 */
 
 /* Comment the following line to use standard mxGetString (slower) */
+#if !defined (HAVE_OCTAVE)
 #define __HACK_MXCHAR__
+#endif
 
 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
@@ -28,18 +35,18 @@
     mxArray *out = NULL;
     
-	/* Check for proper number of arguments. */
+    /* Check for proper number of arguments. */
     if ((nrhs == 0) || (nrhs == 1))
-	    mexErrMsgTxt("Not enough input arguments.");
+        mexErrMsgTxt("Not enough input arguments.");
     else if (nrhs > 4)
-	    mexErrMsgTxt("Too many input arguments.");
+        mexErrMsgTxt("Too many input arguments.");
     else if (nlhs > 1)
         mexErrMsgTxt("Too many output arguments.");
     
     /* The input TEXT must be a string */
-	if (!mxIsChar(prhs[0]))
-	    mexErrMsgTxt("Inputs must be character arrays.");
-	stext = mxGetM(prhs[0]) * mxGetN(prhs[0]);
+    if (!mxIsChar(prhs[0]))
+        mexErrMsgTxt("Inputs must be character arrays.");
+    stext = mxGetM(prhs[0]) * mxGetN(prhs[0]);
 #ifdef __HACK_MXCHAR__
-	text = mxGetData(prhs[0]);
+    text = mxGetData(prhs[0]);
 #else
     text = mxCalloc(stext+1, sizeof(char));
@@ -48,31 +55,31 @@
         
     /* The input PATTERN must be a string */
-	if (!mxIsChar(prhs[1]))
-		mexErrMsgTxt("Inputs must be character arrays.");
+    if (!mxIsChar(prhs[1]))
+        mexErrMsgTxt("Inputs must be character arrays.");
     spattern = mxGetM(prhs[1]) * mxGetN(prhs[1]);
 #ifdef __HACK_MXCHAR__
-	pattern = mxGetData(prhs[1]);
+    pattern = mxGetData(prhs[1]);
 #else
     pattern = mxCalloc(spattern+1, sizeof(char));
-	mxGetString(prhs[1], pattern, spattern+1);
+    mxGetString(prhs[1], pattern, spattern+1);
 #endif
 
-	/* The input INDEX must be an integer */
-	if (nrhs > 2) {
-	    if ((!mxIsNumeric(prhs[2]) || (mxGetM(prhs[2]) * mxGetN(prhs[2]) !=  1)))
-	        mexErrMsgTxt("Index input must be an integer.");
-	    ind = (unsigned int)mxGetScalar(prhs[2]);
-	    if (ind < 1)
-	        mexErrMsgTxt("Index must be greater than 1.");
-	}
-	
-	/* The input OCCUR must be an integer */
-	if (nrhs == 4) {
-	    if ((!mxIsNumeric(prhs[3]) || (mxGetM(prhs[3]) * mxGetN(prhs[3]) !=  1)))
-	        mexErrMsgTxt("Index input must be an integer.");
-	    nboccur = (unsigned int)mxGetScalar(prhs[3]);
-	}
-	
-	/* Find pattern in text */
+    /* The input INDEX must be an integer */
+    if (nrhs > 2) {
+        if ((!mxIsNumeric(prhs[2]) || (mxGetM(prhs[2]) * mxGetN(prhs[2]) !=  1)))
+            mexErrMsgTxt("Index input must be an integer.");
+        ind = (unsigned int)mxGetScalar(prhs[2]);
+        if (ind < 1)
+            mexErrMsgTxt("Index must be greater than 1.");
+    }
+    
+    /* The input OCCUR must be an integer */
+    if (nrhs == 4) {
+        if ((!mxIsNumeric(prhs[3]) || (mxGetM(prhs[3]) * mxGetN(prhs[3]) !=  1)))
+            mexErrMsgTxt("Index input must be an integer.");
+        nboccur = (unsigned int)mxGetScalar(prhs[3]);
+    }
+    
+    /* Find pattern in text */
     for (i=ind-1;i<stext;i++) {
         for (j=0;j<spattern && i+j<stext;j++) {
Index: trunk/src/@xmltree/private/xml_findstr.m
===================================================================
--- trunk/src/@xmltree/private/xml_findstr.m	(revision 820)
+++ trunk/src/@xmltree/private/xml_findstr.m	(revision 925)
@@ -20,9 +20,9 @@
 %
 %   See also STRFIND, FINDSTR
-%_______________________________________________________________________
-% Copyright (C) 2002-2008  http://www.artefact.tk/
+%__________________________________________________________________________
+% Copyright (C) 2002-2011  http://www.artefact.tk/
 
-% Guillaume Flandin <guillaume@artefact.tk>
-% $Id: xml_findstr.m 2271 2008-09-30 21:19:47Z guillaume $
+% Guillaume Flandin
+% $Id: xml_findstr.m 4460 2011-09-05 14:52:16Z guillaume $
 
 %error(sprintf('Missing MEX-file: %s', mfilename));
Index: trunk/src/@xmltree/private/xml_parser.m
===================================================================
--- trunk/src/@xmltree/private/xml_parser.m	(revision 820)
+++ trunk/src/@xmltree/private/xml_parser.m	(revision 925)
@@ -5,17 +5,20 @@
 % xmlstr  - XML string to parse
 % tree    - tree structure corresponding to the XML file
-%_______________________________________________________________________
-%
-% xml_parser.m is an XML 1.0 (http://www.w3.org/TR/REC-xml) parser
-% written in Matlab. It aims to be fully conforming. It is currently not
-% a validating XML processor.
+%__________________________________________________________________________
+%
+% xml_parser.m is an XML 1.0 (http://www.w3.org/TR/REC-xml) parser.
+% It aims to be fully conforming. It is currently not a validating 
+% XML processor.
 %
 % A description of the tree structure provided in output is detailed in 
 % the header of this m-file.
-%_______________________________________________________________________
-% @(#)xml_parser.m              Guillaume Flandin            2002/04/04
-
-% XML Processor for MATLAB (The Mathworks, Inc.).
-% Copyright (C) 2002-2003 Guillaume Flandin <Guillaume@artefact.tk>
+%__________________________________________________________________________
+% Copyright (C) 2002-2015  http://www.artefact.tk/
+
+% Guillaume Flandin
+% $Id: xml_parser.m 6480 2015-06-13 01:08:30Z guillaume $
+
+% XML Processor for GNU Octave and MATLAB (The Mathworks, Inc.)
+% Copyright (C) 2002-2015 Guillaume Flandin <Guillaume@artefact.tk>
 %
 % This program is free software; you can redistribute it and/or
@@ -32,5 +35,5 @@
 % along with this program; if not, write to the Free Software
 % Foundation Inc, 59 Temple Pl. - Suite 330, Boston, MA 02111-1307, USA.
-%-----------------------------------------------------------------------
+%--------------------------------------------------------------------------
 
 % Suggestions for improvement and fixes are always welcome, although no
@@ -39,16 +42,16 @@
 % Check also the latest developments on the following webpage:
 %           <http://www.artefact.tk/software/matlab/xml/>
-%-----------------------------------------------------------------------
+%--------------------------------------------------------------------------
 
 % The implementation of this XML parser is much inspired from a 
-% Javascript parser available at <http://www.jeremie.com/>
-
-% A mex-file xml_findstr.c is also required, to encompass some
-% limitations of the built-in findstr Matlab function.
+% Javascript parser that used to be available at <http://www.jeremie.com/>
+
+% A C-MEX file xml_findstr.c is also required, to encompass some
+% limitations of the built-in FINDSTR function.
 % Compile it on your architecture using 'mex -O xml_findstr.c' command
 % if the compiled version for your system is not provided.
-% If this function behaves badly (crash or wrong results), comment the
-% line '#define __HACK_MXCHAR__' in xml_findstr.c and compile it again.
-%-----------------------------------------------------------------------
+% If this function does not behave as expected, comment the line
+% '#define __HACK_MXCHAR__' in xml_findstr.c and compile it again.
+%--------------------------------------------------------------------------
 
 % Structure of the output tree:
@@ -91,5 +94,5 @@
 %       |_ uid:    double
 %
-%-----------------------------------------------------------------------
+%--------------------------------------------------------------------------
 
 % TODO/BUG/FEATURES:
@@ -103,5 +106,5 @@
 %  - xml_findstr is indeed xml_strfind according to Mathworks vocabulary
 %  - problem with entities: do we need to convert them here? (&eacute;)
-%-----------------------------------------------------------------------
+%--------------------------------------------------------------------------
 
 %- XML string to parse and number of tags read
@@ -109,9 +112,9 @@
 
 %- Check input arguments
-error(nargchk(1,1,nargin));
+%error(nargchk(1,1,nargin));
 if isempty(xmlstr)
-	error('[XML] Not enough parameters.')
-elseif ~isstr(xmlstr) | sum(size(xmlstr)>1)>1
-	error('[XML] Input must be a string.')
+    error('[XML] Not enough parameters.')
+elseif ~ischar(xmlstr) || sum(size(xmlstr)>1)>1
+    error('[XML] Input must be a string.')
 end
 
@@ -137,285 +140,282 @@
 clear global xmlstring Xparse_count xtree;
 
-%=======================================================================
+%==========================================================================
 % SUBFUNCTIONS
 
-%-----------------------------------------------------------------------
+%--------------------------------------------------------------------------
 function frag = compile(frag)
-	global xmlstring xtree Xparse_count;
-	
-	while 1,
-		if length(xmlstring)<=frag.str | ...
-		   (frag.str == length(xmlstring)-1 & strcmp(xmlstring(frag.str:end),' '))
-			return
-		end
-		TagStart = xml_findstr(xmlstring,'<',frag.str,1);
-		if isempty(TagStart)
-			%- Character data
-			error(sprintf(['[XML] Unknown data at the end of the XML file.\n' ...
-			'      Please send me your XML file at Guillaume@artefact.tk']));
-			xtree{Xparse_count} = chardata;
-			xtree{Xparse_count}.value = erode(entity(xmlstring(frag.str:end)));
-			xtree{Xparse_count}.parent = frag.parent;
-			xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
-			frag.str = '';
-		elseif TagStart > frag.str
-			if strcmp(xmlstring(frag.str:TagStart-1),' ')
-				%- A single white space before a tag (ignore)
-				frag.str = TagStart;
-			else
-				%- Character data
-				xtree{Xparse_count} = chardata;
-				xtree{Xparse_count}.value = erode(entity(xmlstring(frag.str:TagStart-1)));
-				xtree{Xparse_count}.parent = frag.parent;
-				xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
-				frag.str = TagStart;
-			end
-		else 
-			if strcmp(xmlstring(frag.str+1),'?')
-				%- Processing instruction
-				frag = tag_pi(frag);
-			else
-				if length(xmlstring)-frag.str>4 & strcmp(xmlstring(frag.str+1:frag.str+3),'!--')
-					%- Comment
-					frag = tag_comment(frag);
-				else
-					if length(xmlstring)-frag.str>9 & strcmp(xmlstring(frag.str+1:frag.str+8),'![CDATA[')
-						%- Litteral data
-						frag = tag_cdata(frag);
-					else
-						%- A tag element (empty (<.../>) or not)
-						if ~isempty(frag.end)
-							endmk = ['/' frag.end '>'];
-						else 
-							endmk = '/>';
-						end
-						if strcmp(xmlstring(frag.str+1:frag.str+length(frag.end)+2),endmk) | ...
-							strcmp(strip(xmlstring(frag.str+1:frag.str+length(frag.end)+2)),endmk)
-							frag.str = frag.str + length(frag.end)+3;
-							return
-						else
-							frag = tag_element(frag);
-						end
-					end
-				end
-			end
-		end
-	end
-
-%-----------------------------------------------------------------------
+    global xmlstring xtree Xparse_count;
+    
+    while 1,
+        if length(xmlstring)<=frag.str || ...
+           (frag.str == length(xmlstring)-1 && strcmp(xmlstring(frag.str:end),' '))
+            return
+        end
+        TagStart = xml_findstr(xmlstring,'<',frag.str,1);
+        if isempty(TagStart)
+            %- Character data
+            error('[XML] Unknown data at the end of the XML file.');
+            Xparse_count = Xparse_count + 1;
+            xtree{Xparse_count} = chardata;
+            xtree{Xparse_count}.value = erode(entity(xmlstring(frag.str:end)));
+            xtree{Xparse_count}.parent = frag.parent;
+            xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
+            frag.str = '';
+        elseif TagStart > frag.str
+            if strcmp(xmlstring(frag.str:TagStart-1),' ')
+                %- A single white space before a tag (ignore)
+                frag.str = TagStart;
+            else
+                %- Character data
+                Xparse_count = Xparse_count + 1;
+                xtree{Xparse_count} = chardata;
+                xtree{Xparse_count}.value = erode(entity(xmlstring(frag.str:TagStart-1)));
+                xtree{Xparse_count}.parent = frag.parent;
+                xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
+                frag.str = TagStart;
+            end
+        else 
+            if strcmp(xmlstring(frag.str+1),'?')
+                %- Processing instruction
+                frag = tag_pi(frag);
+            else
+                if length(xmlstring)-frag.str>4 && strcmp(xmlstring(frag.str+1:frag.str+3),'!--')
+                    %- Comment
+                    frag = tag_comment(frag);
+                else
+                    if length(xmlstring)-frag.str>9 && strcmp(xmlstring(frag.str+1:frag.str+8),'![CDATA[')
+                        %- Litteral data
+                        frag = tag_cdata(frag);
+                    else
+                        %- A tag element (empty (<.../>) or not)
+                        if ~isempty(frag.end)
+                            endmk = ['/' frag.end '>'];
+                        else 
+                            endmk = '/>';
+                        end
+                        if strcmp(xmlstring(frag.str+1:frag.str+length(frag.end)+2),endmk) || ...
+                            strcmp(strip(xmlstring(frag.str+1:frag.str+length(frag.end)+2)),endmk)
+                            frag.str = frag.str + length(frag.end)+3;
+                            return
+                        else
+                            frag = tag_element(frag);
+                        end
+                    end
+                end
+            end
+        end
+    end
+
+%--------------------------------------------------------------------------
 function frag = tag_element(frag)
-	global xmlstring xtree Xparse_count;
-	close =  xml_findstr(xmlstring,'>',frag.str,1);
-	if isempty(close)
-		error('[XML] Tag < opened but not closed.');
-	else
-		empty = strcmp(xmlstring(close-1:close),'/>');
-		if empty
-			close = close - 1;
-		end
-		starttag = normalize(xmlstring(frag.str+1:close-1));
-		nextspace = xml_findstr(starttag,' ',1,1);
-		attribs = '';
-		if isempty(nextspace)
-			name = starttag;
-		else
-			name = starttag(1:nextspace-1);
-			attribs = starttag(nextspace+1:end);
-		end
-		xtree{Xparse_count} = element;
-		xtree{Xparse_count}.name = strip(name);
-		if frag.parent
-			xtree{Xparse_count}.parent = frag.parent;
-			xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
-		end
-		if length(attribs) > 0
-			xtree{Xparse_count}.attributes = attribution(attribs);
-		end
-		if ~empty
-			contents = fragment;
-			contents.str = close+1;
-			contents.end = name;
-			contents.parent = Xparse_count;
-			contents = compile(contents);
-			frag.str = contents.str;
-		else
-			frag.str = close+2;
-		end
-	end
-
-%-----------------------------------------------------------------------
+    global xmlstring xtree Xparse_count;
+    close =  xml_findstr(xmlstring,'>',frag.str,1);
+    if isempty(close)
+        error('[XML] Tag < opened but not closed.');
+    else
+        empty = strcmp(xmlstring(close-1:close),'/>');
+        if empty
+            close = close - 1;
+        end
+        starttag = normalize(xmlstring(frag.str+1:close-1));
+        nextspace = xml_findstr(starttag,' ',1,1);
+        attribs = '';
+        if isempty(nextspace)
+            name = starttag;
+        else
+            name = starttag(1:nextspace-1);
+            attribs = starttag(nextspace+1:end);
+        end
+        Xparse_count = Xparse_count + 1;
+        xtree{Xparse_count} = element;
+        xtree{Xparse_count}.name = strip(name);
+        if frag.parent
+            xtree{Xparse_count}.parent = frag.parent;
+            xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
+        end
+        if ~isempty(attribs)
+            xtree{Xparse_count}.attributes = attribution(attribs);
+        end
+        if ~empty
+            contents = fragment;
+            contents.str = close+1;
+            contents.end = name;
+            contents.parent = Xparse_count;
+            contents = compile(contents);
+            frag.str = contents.str;
+        else
+            frag.str = close+2;
+        end
+    end
+
+%--------------------------------------------------------------------------
 function frag = tag_pi(frag)
-	global xmlstring xtree Xparse_count;
-	close = xml_findstr(xmlstring,'?>',frag.str,1);
-	if isempty(close)
-		warning('[XML] Tag <? opened but not closed.')
-	else
-		nextspace = xml_findstr(xmlstring,' ',frag.str,1);
-		xtree{Xparse_count} = pri;
-		if nextspace > close | nextspace == frag.str+2
-			xtree{Xparse_count}.value = erode(xmlstring(frag.str+2:close-1));
-		else
-			xtree{Xparse_count}.value = erode(xmlstring(nextspace+1:close-1));
-			xtree{Xparse_count}.target = erode(xmlstring(frag.str+2:nextspace));
-		end
-		if frag.parent
-			xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
-			xtree{Xparse_count}.parent = frag.parent;
-		end
-		frag.str = close+2;
-	end
-
-%-----------------------------------------------------------------------
+    global xmlstring xtree Xparse_count;
+    close = xml_findstr(xmlstring,'?>',frag.str,1);
+    if isempty(close)
+        warning('[XML] Tag <? opened but not closed.')
+    else
+        nextspace = xml_findstr(xmlstring,' ',frag.str,1);
+        Xparse_count = Xparse_count + 1;
+        xtree{Xparse_count} = pri;
+        if nextspace > close || nextspace == frag.str+2
+            xtree{Xparse_count}.value = erode(xmlstring(frag.str+2:close-1));
+        else
+            xtree{Xparse_count}.value = erode(xmlstring(nextspace+1:close-1));
+            xtree{Xparse_count}.target = erode(xmlstring(frag.str+2:nextspace));
+        end
+        if frag.parent
+            xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
+            xtree{Xparse_count}.parent = frag.parent;
+        end
+        frag.str = close+2;
+    end
+
+%--------------------------------------------------------------------------
 function frag = tag_comment(frag)
-	global xmlstring xtree Xparse_count;
-	close = xml_findstr(xmlstring,'-->',frag.str,1);
-	if isempty(close)
-		warning('[XML] Tag <!-- opened but not closed.')
-	else
-		xtree{Xparse_count} = comment;
-		xtree{Xparse_count}.value = erode(xmlstring(frag.str+4:close-1));
-		if frag.parent
-			xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
-			xtree{Xparse_count}.parent = frag.parent;
-		end
-		frag.str = close+3;
-	end
-
-%-----------------------------------------------------------------------
+    global xmlstring xtree Xparse_count;
+    close = xml_findstr(xmlstring,'-->',frag.str,1);
+    if isempty(close)
+        warning('[XML] Tag <!-- opened but not closed.')
+    else
+        Xparse_count = Xparse_count + 1;
+        xtree{Xparse_count} = comment;
+        xtree{Xparse_count}.value = erode(xmlstring(frag.str+4:close-1));
+        if frag.parent
+            xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
+            xtree{Xparse_count}.parent = frag.parent;
+        end
+        frag.str = close+3;
+    end
+
+%--------------------------------------------------------------------------
 function frag = tag_cdata(frag)
-	global xmlstring xtree Xparse_count;
-	close = xml_findstr(xmlstring,']]>',frag.str,1);
-	if isempty(close)
-		warning('[XML] Tag <![CDATA[ opened but not closed.')
-	else
-		xtree{Xparse_count} = cdata;
-		xtree{Xparse_count}.value = xmlstring(frag.str+9:close-1);
-		if frag.parent
-			xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
-			xtree{Xparse_count}.parent = frag.parent;
-		end
-		frag.str = close+3;
-	end
-
-%-----------------------------------------------------------------------
+    global xmlstring xtree Xparse_count;
+    close = xml_findstr(xmlstring,']]>',frag.str,1);
+    if isempty(close)
+        warning('[XML] Tag <![CDATA[ opened but not closed.')
+    else
+        Xparse_count = Xparse_count + 1;
+        xtree{Xparse_count} = cdata;
+        xtree{Xparse_count}.value = xmlstring(frag.str+9:close-1);
+        if frag.parent
+            xtree{frag.parent}.contents = [xtree{frag.parent}.contents Xparse_count];
+            xtree{Xparse_count}.parent = frag.parent;
+        end
+        frag.str = close+3;
+    end
+
+%--------------------------------------------------------------------------
 function all = attribution(str)
-	%- Initialize attributs
-	nbattr = 0;
-	all = cell(nbattr);
-	%- Look for 'key="value"' substrings
-	while 1,
-		eq = xml_findstr(str,'=',1,1);
-		if isempty(str) | isempty(eq), return; end
-		id = xml_findstr(str,'"',1,1);       % should also look for ''''
-		nextid = xml_findstr(str,'"',id+1,1);% rather than only '"'
-		nbattr = nbattr + 1;
-		all{nbattr}.key = strip(str(1:(eq-1)));
-		all{nbattr}.val = entity(str((id+1):(nextid-1)));
-		str = str((nextid+1):end);
-	end
-
-%-----------------------------------------------------------------------
+    %- Initialize attributs
+    nbattr = 0;
+    all = cell(nbattr);
+    %- Look for 'key="value"' substrings
+    while 1,
+        eq = xml_findstr(str,'=',1,1);
+        if isempty(str) || isempty(eq), return; end
+        id = sort([xml_findstr(str,'"',1,1),xml_findstr(str,'''',1,1)]); id=id(1);
+        nextid = sort([xml_findstr(str,'"',id+1,1),xml_findstr(str,'''',id+1,1)]);nextid=nextid(1);
+        nbattr = nbattr + 1;
+        all{nbattr}.key = strip(str(1:(eq-1)));
+        all{nbattr}.val = entity(str((id+1):(nextid-1)));
+        str = str((nextid+1):end);
+    end
+
+%--------------------------------------------------------------------------
 function elm = element
-	global Xparse_count;
-	Xparse_count = Xparse_count + 1;
-	elm = struct('type','element','name','','attributes',[],'contents',[],'parent',[],'uid',Xparse_count);
+    global Xparse_count;
+    elm = struct('type','element','name','','attributes',[],'contents',[],'parent',[],'uid',Xparse_count);
    
-%-----------------------------------------------------------------------
+%--------------------------------------------------------------------------
 function cdat = chardata
-	global Xparse_count;
-	Xparse_count = Xparse_count + 1;
-	cdat = struct('type','chardata','value','','parent',[],'uid',Xparse_count);
+    global Xparse_count;
+    cdat = struct('type','chardata','value','','parent',[],'uid',Xparse_count);
    
-%-----------------------------------------------------------------------
+%--------------------------------------------------------------------------
 function cdat = cdata
-	global Xparse_count;
-	Xparse_count = Xparse_count + 1;
-	cdat = struct('type','cdata','value','','parent',[],'uid',Xparse_count);
+    global Xparse_count;
+    cdat = struct('type','cdata','value','','parent',[],'uid',Xparse_count);
    
-%-----------------------------------------------------------------------
+%--------------------------------------------------------------------------
 function proce = pri
-	global Xparse_count;
-	Xparse_count = Xparse_count + 1;
-	proce = struct('type','pi','value','','target','','parent',[],'uid',Xparse_count);
-
-%-----------------------------------------------------------------------
+    global Xparse_count;
+    proce = struct('type','pi','value','','target','','parent',[],'uid',Xparse_count);
+
+%--------------------------------------------------------------------------
 function commt = comment
-	global Xparse_count;
-	Xparse_count = Xparse_count + 1;
-	commt = struct('type','comment','value','','parent',[],'uid',Xparse_count);
-
-%-----------------------------------------------------------------------
+    global Xparse_count;
+    commt = struct('type','comment','value','','parent',[],'uid',Xparse_count);
+
+%--------------------------------------------------------------------------
 function frg = fragment
-	frg = struct('str','','parent','','end','');
-
-%-----------------------------------------------------------------------
+    frg = struct('str','','parent','','end','');
+
+%--------------------------------------------------------------------------
 function str = prolog(str)
-	%- Initialize beginning index of elements tree
-	b = 1;
-	%- Initial tag
-	start = xml_findstr(str,'<',1,1);
-	if isempty(start) 
-		error('[XML] No tag found.')
-	end
-	%- Header (<?xml version="1.0" ... ?>)
-	if strcmp(lower(str(start:start+2)),'<?x')
-		close = xml_findstr(str,'?>',1,1);
-		if ~isempty(close) 
-			b = close + 2;
-		else 
-			warning('[XML] Header tag incomplete.')
-		end
-	end
-	%- Doctype (<!DOCTYPE type ... [ declarations ]>)
-	start = xml_findstr(str,'<!DOCTYPE',b,1);  % length('<!DOCTYPE') = 9
-	if ~isempty(start) 
-		close = xml_findstr(str,'>',start+9,1);
-		if ~isempty(close)
-			b = close + 1;
-			dp = xml_findstr(str,'[',start+9,1);
-			if (~isempty(dp) & dp < b)
-				k = xml_findstr(str,']>',start+9,1);
-				if ~isempty(k)
-					b = k + 2;
-				else
-					warning('[XML] Tag [ in DOCTYPE opened but not closed.')
-				end
-			end
-		else
-			warning('[XML] Tag DOCTYPE opened but not closed.')
-		end
-	end
-	%- Skip prolog from the xml string
-	str = str(b:end);
-
-%-----------------------------------------------------------------------
+    %- Initialize beginning index of elements tree
+    b = 1;
+    %- Initial tag
+    start = xml_findstr(str,'<',1,1);
+    if isempty(start) 
+        error('[XML] No tag found.')
+    end
+    %- Header (<?xml version="1.0" ... ?>)
+    if strcmpi(str(start:start+2),'<?x')
+        close = xml_findstr(str,'?>',1,1);
+        if ~isempty(close) 
+            b = close + 2;
+        else 
+            warning('[XML] Header tag incomplete.')
+        end
+    end
+    %- Doctype (<!DOCTYPE type ... [ declarations ]>)
+    start = xml_findstr(str,'<!DOCTYPE',b,1);  % length('<!DOCTYPE') = 9
+    if ~isempty(start) 
+        close = xml_findstr(str,'>',start+9,1);
+        if ~isempty(close)
+            b = close + 1;
+            dp = xml_findstr(str,'[',start+9,1);
+            if (~isempty(dp) && dp < b)
+                k = xml_findstr(str,']>',start+9,1);
+                if ~isempty(k)
+                    b = k + 2;
+                else
+                    warning('[XML] Tag [ in DOCTYPE opened but not closed.')
+                end
+            end
+        else
+            warning('[XML] Tag DOCTYPE opened but not closed.')
+        end
+    end
+    %- Skip prolog from the xml string
+    str = str(b:end);
+
+%--------------------------------------------------------------------------
 function str = strip(str)
-	a = isspace(str);
-	a = find(a==1);
-	str(a) = '';
-
-%-----------------------------------------------------------------------
+    str(isspace(str)) = '';
+
+%--------------------------------------------------------------------------
 function str = normalize(str)
-	% Find white characters (space, newline, carriage return, tabs, ...)
-	i = isspace(str);
-	i = find(i == 1);
-	str(i) = ' ';
-	% replace several white characters by only one
-	if ~isempty(i)
-		j = i - [i(2:end) i(end)];
-		k = find(j == -1);
-		str(i(k)) = [];
-	end
-
-%-----------------------------------------------------------------------
+    % Find white characters (space, newline, carriage return, tabs, ...)
+    i = isspace(str);
+    i = find(i == 1);
+    str(i) = ' ';
+    % replace several white characters by only one
+    if ~isempty(i)
+        j = i - [i(2:end) i(end)];
+        str(i(j == -1)) = [];
+    end
+
+%--------------------------------------------------------------------------
 function str = entity(str)
-	str = strrep(str,'&lt;','<');
-	str = strrep(str,'&gt;','>');
-	str = strrep(str,'&quot;','"');
-	str = strrep(str,'&apos;','''');
-	str = strrep(str,'&amp;','&');
+    str = strrep(str,'&lt;','<');
+    str = strrep(str,'&gt;','>');
+    str = strrep(str,'&quot;','"');
+    str = strrep(str,'&apos;','''');
+    str = strrep(str,'&amp;','&');
    
-%-----------------------------------------------------------------------
+%--------------------------------------------------------------------------
 function str = erode(str)
-	if ~isempty(str) & str(1)==' ' str(1)=''; end;
-	if ~isempty(str) & str(end)==' ' str(end)=''; end;
+    if ~isempty(str) && str(1)==' ', str(1)=''; end;
+    if ~isempty(str) && str(end)==' ', str(end)=''; end;
