Mercurial > forge
changeset 12068:04518dae1bbd octave-forge
New functions needed for OCT interface
author | prnienhuis |
---|---|
date | Fri, 27 Sep 2013 18:03:12 +0000 |
parents | 7e45cfe678cb |
children | 0bb773b19abf |
files | main/io/inst/getxmlattv.m main/io/inst/getxmlnode.m |
diffstat | 2 files changed, 103 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/io/inst/getxmlattv.m Fri Sep 27 18:03:12 2013 +0000 @@ -0,0 +1,47 @@ +## Copyright (C) 2013 Philip Nienhuis +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} [@var{retval}] = getxmlattv (@var{xmlnode}, @var{att}) +## Get value of attribute @var{att} in xml node in string @var{xmlnode}. +## of an xml string, return empty if attribute isn't present. +## +## @seealso{} +## @end deftypefn + +## Author: Philip Nienhuis <prnienhuis@ at users.sf.net> +## Created: 2013-09-08 + +function [retval] = getxmlattv (xmlnode, att) + + retval = ''; + + ## Get end of first tag + iend = index (xmlnode, ">"); + ## Get start of value string. Concat '="' to ensure minimal ambiguity + vals = index (xmlnode, [att '="']); + if (vals == 0) + ## Attribute not in current tag + return + elseif (vals) + vals = vals + length (att) + 2; + vale = regexp (xmlnode(vals:end), '"[ >/]'); + if (! isempty (vale)) + retval = xmlnode(vals:vals+vale-2); + endif + endif + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/io/inst/getxmlnode.m Fri Sep 27 18:03:12 2013 +0000 @@ -0,0 +1,56 @@ +## Copyright (C) 2013 Philip Nienhuis +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{node} =} getxmlnode (@var{xml}, @var{nname}) +## @deftypefnx {Function File} {@var{node} =} getxmlnode (@var{xml}, @var{nname}, @var{is}) +## Get string representing the first xml node @var{nname} from xml file in +## string @var{xml}, optionally starting at position @var{is}, and return +## start and end indices. +## +## @seealso{} +## @end deftypefn + +## Author: Philip Nienhuis <prnienhuis at users.sf.net> +## Created: 2013-09-08 + +function [ node, spos, epos ] = getxmlnode (xml, nname, is=1) + + node = ''; + spos = index (xml(is:end), ["<" nname]); + if (spos) + ## Apparently a node exists. Get its end. Maybe it is a single node + ## ending in "/>" + epos = index (xml(is+spos:end), "/>"); + ## Do check if the "/>" really belongs to this node + if ((! epos) || index (xml(is+spos:is+spos+epos), "><")) + ## Apparently it is a composite node + epos = index (xml(is+spos:end), ["</" nname ">"]); + if (! epos) + ## Apparently the xml is invalid? + error ("getxmlnode: couldn't find matching end tag for %s", nname); + endif + epos = is + spos + epos + length (nname) + 1; + else + epos = is + spos + epos; + endif + spos = is + spos - 1; + node = xml(spos:epos); + else + epos = 0; + endif + +endfunction