2
* Copyright (C) 2004 Laurent Mazet
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; If not, see <http://www.gnu.org/licenses/>.
22
#include <octave/oct.h>
23
#include <octave/lo-ieee.h>
24
#include <octave/oct-map.h>
25
#include <octave/Cell.h>
29
#include "xmltree_read.h"
32
octave_value get_element (element *root) {
33
int length, rows, columns;
35
string_vector tmp_array;
36
ComplexMatrix tmp_matrix;
37
Octave_map tmp_structure;
39
octave_value_list tmp_list;
46
switch (root->def_value) {
48
switch (root->const_value) {
49
case const_true: retval = octave_value(true); break;
50
case const_false: retval = octave_value(false); break;
51
case const_inf: retval = octave_value(octave_Inf); break;
52
case const_neginf: retval = octave_value(-octave_Inf); break;
53
case const_nan: retval = octave_value(octave_NaN); break;
54
case const_na: retval = octave_value(octave_NA); break;
55
case const_undef: retval = octave_value(root->scalar_value); break;
61
octave_value(Complex(get_element(root->child).double_value(),
62
get_element(root->child->next).double_value()));
66
retval = octave_value(root->string_value);
72
tmp_array = string_vector(rows);
73
for (int k=0; (k<rows) && (root); k++, root = root->next)
74
tmp_array(k) = get_element(root).string_value();
75
retval = octave_value(tmp_array);
80
columns = root->columns;
82
tmp_matrix = ComplexMatrix(rows, columns);
83
for (int k=0; (k<rows) && (root); k++)
84
for (int l=0; (l<columns) && (root); l++, root = root->next)
85
tmp_matrix(k, l) = get_element(root).complex_value();
86
if (tmp_matrix.all_elements_are_real())
87
retval = octave_value(real(tmp_matrix));
89
retval = octave_value(tmp_matrix);
94
for (int k=0; root; root = root->next)
96
tmp_structure.assign(root->name, get_element(root));
98
char *name = new char[7];
99
sprintf (name, "__%04d", k++);
100
warning ("no field name in structure.");
101
tmp_structure.assign(name, get_element(root));
104
retval = octave_value(tmp_structure);
108
length = root->length;
110
//tmp_list = octave_value_list(length);
111
for (int k=0; (k<length) && (root); k++, root = root->next)
112
tmp_list(k) = get_element(root);
113
retval = octave_value(tmp_list);
118
columns = root->columns;
120
tmp_cell = Cell(rows, columns);
121
for (int k=0; (k<rows) && (root); k++)
122
for (int l=0; (l<columns) && (root); l++, root = root->next)
123
tmp_cell(k, l) = get_element(root);
124
retval = octave_value(tmp_cell);
128
warning ("unknown type.\n");
134
DEFUN_DLD (xmlread, args, nargout,
136
"@deftypefn {Function File} {@var{value}} xmlread(@var{filename})\n"
138
"Read a @var{value} from @var{filename} as an XML file\n"
142
if (args.length() != 1) {
144
return octave_value_list();
148
std::string filename = args(0).string_value();
149
element *root = read_xmltree(filename.c_str());
151
return octave_value_list();
153
/* step down into the element tree */
154
octave_value retval = get_element (root->child);