source: trunk/src/uvmat_doc/FUNCTIONS_DOC/parseXML.html @ 37

Last change on this file since 37 was 37, checked in by sommeria, 14 years ago

create_grid.fig ,
uvmat_doc and all the included files added

File size: 6.8 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2                "http://www.w3.org/TR/REC-html40/loose.dtd">
3<html>
4<head>
5  <title>Description of parseXML</title>
6  <meta name="keywords" content="parseXML">
7  <meta name="description" content="PARSEXML Convert XML file to a MATLAB structure. (from matlab help)">
8  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
9  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
10  <meta name="robots" content="index, follow">
11  <link type="text/css" rel="stylesheet" href="../m2html.css">
12</head>
13<body>
14<a name="_top"></a>
15<div><a href="../index.html">Home</a> &gt;  <a href="index.html">.</a> &gt; parseXML.m</div>
16
17<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
18<td align="right"><a href="index.html">Index for .&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->
19
20<h1>parseXML
21</h1>
22
23<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
24<div class="box"><strong>PARSEXML Convert XML file to a MATLAB structure. (from matlab help)</strong></div>
25
26<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
27<div class="box"><strong>function theStruct = parseXML(filename) </strong></div>
28
29<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
30<div class="fragment"><pre class="comment"> PARSEXML Convert XML file to a MATLAB structure. (from matlab help)</pre></div>
31
32<!-- crossreference -->
33<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
34This function calls:
35<ul style="list-style-image:url(../matlabicon.gif)">
36</ul>
37This function is called by:
38<ul style="list-style-image:url(../matlabicon.gif)">
39</ul>
40<!-- crossreference -->
41
42<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
43<ul style="list-style-image:url(../matlabicon.gif)">
44<li><a href="#_sub1" class="code">function children = parseChildNodes(theNode)</a></li><li><a href="#_sub2" class="code">function nodeStruct = makeStructFromNode(theNode)</a></li><li><a href="#_sub3" class="code">function attributes = parseAttributes(theNode)</a></li></ul>
45<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
46<div class="fragment"><pre>0001 <span class="comment">% PARSEXML Convert XML file to a MATLAB structure. (from matlab help)</span>
470002 <a name="_sub0" href="#_subfunctions" class="code">function theStruct = parseXML(filename)</a>
480003
490004 <span class="keyword">try</span>
500005    tree = xmlread(filename);
510006 <span class="keyword">catch</span>
520007    error(<span class="string">'Failed to read XML file %s.'</span>,filename);
530008 <span class="keyword">end</span>
540009
550010 <span class="comment">% Recurse over child nodes. This could run into problems</span>
560011 <span class="comment">% with very deeply nested trees.</span>
570012 <span class="keyword">try</span>
580013    theStruct = <a href="#_sub1" class="code" title="subfunction children = parseChildNodes(theNode)">parseChildNodes</a>(tree);
590014 <span class="keyword">catch</span>
600015    error(<span class="string">'Unable to parse XML file %s.'</span>);
610016 <span class="keyword">end</span>
620017
630018
640019 <span class="comment">% ----- Subfunction PARSECHILDNODES -----</span>
650020 <a name="_sub1" href="#_subfunctions" class="code">function children = parseChildNodes(theNode)</a>
660021 <span class="comment">% Recurse over node children.</span>
670022 children = [];
680023 <span class="keyword">if</span> theNode.hasChildNodes
690024    childNodes = theNode.getChildNodes;
700025    numChildNodes = childNodes.getLength;
710026    allocCell = cell(1, numChildNodes);
720027
730028    children = struct(             <span class="keyword">...</span>
740029       <span class="string">'Name'</span>, allocCell, <span class="string">'Attributes'</span>, allocCell,    <span class="keyword">...</span>
750030       <span class="string">'Data'</span>, allocCell, <span class="string">'Children'</span>, allocCell);
760031
770032     <span class="keyword">for</span> count = 1:numChildNodes
780033         theChild = childNodes.item(count-1);
790034         children(count) = <a href="#_sub2" class="code" title="subfunction nodeStruct = makeStructFromNode(theNode)">makeStructFromNode</a>(theChild);
800035     <span class="keyword">end</span>
810036 <span class="keyword">end</span>
820037
830038 <span class="comment">% ----- Subfunction MAKESTRUCTFROMNODE -----</span>
840039 <a name="_sub2" href="#_subfunctions" class="code">function nodeStruct = makeStructFromNode(theNode)</a>
850040 <span class="comment">% Create structure of node info.</span>
860041
870042 nodeStruct = struct(                        <span class="keyword">...</span>
880043    <span class="string">'Name'</span>, char(theNode.getNodeName),       <span class="keyword">...</span>
890044    <span class="string">'Attributes'</span>, <a href="#_sub3" class="code" title="subfunction attributes = parseAttributes(theNode)">parseAttributes</a>(theNode),  <span class="keyword">...</span>
900045    <span class="string">'Data'</span>, <span class="string">''</span>,                              <span class="keyword">...</span>
910046    <span class="string">'Children'</span>, <a href="#_sub1" class="code" title="subfunction children = parseChildNodes(theNode)">parseChildNodes</a>(theNode));
920047
930048 <span class="keyword">if</span> any(strcmp(methods(theNode), <span class="string">'getData'</span>))
940049    nodeStruct.Data = char(theNode.getData);
950050 <span class="keyword">else</span>
960051    nodeStruct.Data = <span class="string">''</span>;
970052 <span class="keyword">end</span>
980053
990054 <span class="comment">% ----- Subfunction PARSEATTRIBUTES -----</span>
1000055 <a name="_sub3" href="#_subfunctions" class="code">function attributes = parseAttributes(theNode)</a>
1010056 <span class="comment">% Create attributes structure.</span>
1020057
1030058 attributes = [];
1040059 <span class="keyword">if</span> theNode.hasAttributes
1050060    theAttributes = theNode.getAttributes;
1060061    numAttributes = theAttributes.getLength;
1070062    allocCell = cell(1, numAttributes);
1080063    attributes = struct(<span class="string">'Name'</span>, allocCell, <span class="string">'Value'</span>, allocCell);
1090064
1100065    <span class="keyword">for</span> count = 1:numAttributes
1110066       attrib = theAttributes.item(count-1);
1120067       attributes(count).Name = char(attrib.getName);
1130068       attributes(count).Value = char(attrib.getValue);
1140069    <span class="keyword">end</span>
1150070 <span class="keyword">end</span></pre></div>
116<hr><address>Generated on Fri 13-Nov-2009 11:17:03 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
117</body>
118</html>
Note: See TracBrowser for help on using the repository browser.