help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML in Octave


From: Andy Pugh
Subject: Re: XML in Octave
Date: Tue, 7 Mar 2006 13:50:52 +0000

On 3/7/06, Bill Denney <address@hidden> wrote:

> Is there any more documentation on these functions?  They don't go into
> practically any detail when I type help xml(read|write).

FWIW I am trying to parse some xml files in Matlab today. The Matlab
help isn't any, err, help either. You need to get the data out using
things with names like Java and DOM and suchlike I have no knowledge
of.

I am using text files input and sscanf, which might be easier for you too.

As an example (and I don't have Octave here so don't know if it works
the same way) these are from the Matlab help. It doesn't look like
Matlab or Octave to me..




infoLabel = 'Plot Tools';
infoCbk = '';
itemFound = false;

xDoc = xmlread(fullfile(matlabroot, ...
               'toolbox/matlab/general/info.xml'));

% Find a deep list of all listitem elements.
allListItems = xDoc.getElementsByTagName('listitem');

% Note that the item list index is zero-based.
for k = 0:allListItems.getLength-1
   thisListItem = allListItems.item(k);
   childNode = thisListItem.getFirstChild;

   while ~isempty(childNode)
      %Filter out text, comments, and processing instructions.
      if childNode.getNodeType == childNode.ELEMENT_NODE
         % Assume that each element has a single
         % org.w3c.dom.Text child.
         childText = char(childNode.getFirstChild.getData);

         switch char(childNode.getTagName)
         case 'label';
            itemFound = strcmp(childText, infoLabel);
         case 'callback' ;
            infoCbk = childText;
         end
      end  % End IF
      childNode = childNode.getNextSibling;
   end  % End WHILE

   if itemFound
      break;
   else
      infoCbk = '';
   end
end  % End FOR

disp(sprintf('Item "%s" has a callback of "%s".', ...
             infoLabel, infoCbk))





--
atp



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]