source: sources/src/dataFormatXmlNode.cc @ 1439:b23bfdd8a935

Revision 1439:b23bfdd8a935, 4.3 KB checked in by niam, 2 years ago (diff)

change contact info

Line 
1/***************************************************************************
2 *            dataFormatXmlNode.cc
3 *
4 *  Wed Nov 30 2005
5 *  Copyright  2005  Dmytro Milinevskyy
6 *  milinevskyy@gmail.com
7 ****************************************************************************/
8
9/*
10 *  This program is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU Lesser General Public License version 2.1 as published by
12 *  the Free Software Foundation;
13 *
14 *  This program is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU Library General Public License for more details.
18 *
19 *  You should have received a copy of the GNU Lesser General Public License
20 *  along with this program; if not, write to the Free Software
21 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24/**
25 * vim indentation settings
26 * set tabstop=4
27 * set shiftwidth=4
28 */
29
30#include <libdodo/directives.h>
31
32#include <libdodo/dataFormatXmlNode.h>
33#include <libdodo/toolsMisc.h>
34#include <libdodo/types.h>
35
36using namespace dodo::data::format::xml;
37
38node::node() : CDATA(false)
39{
40}
41
42//-------------------------------------------------------------------
43
44node::node(const dodo::string    &name,
45           const dodoStringMap &attributes,
46           const dodo::string    &value,
47           const dodo::string    &a_ns) : attributes(attributes),
48                                        name(name),
49                                        nodeValue(value),
50                                        CDATA(false)
51{
52    ns.prefix = a_ns;
53}
54
55//-------------------------------------------------------------------
56
57void
58node::addChild(const node &child)
59{
60    nodeChildren[child.name].push_back(child);
61}
62
63//-------------------------------------------------------------------
64
65void
66node::setChildren(const dodoArray<node> &a_children)
67{
68    dodoArray<node>::const_iterator i = a_children.begin(), j = a_children.end();
69    for (; i != j; ++i)
70        nodeChildren[i->name].push_back(*i);
71}
72
73//-------------------------------------------------------------------
74
75dodoArray<node>
76node::children(const dodo::string &name,
77               bool             recursive)
78{
79    dodoArray<node> nodes = nodeChildren[name];
80
81    if (recursive) {
82        dodoArray<node> subnodes;
83
84        dodoArray<node>::iterator i = nodes.begin(), j = nodes.end();
85        for (; i != j; ++i) {
86            subnodes = i->children(name, true);
87
88            nodes.insert(nodes.end(), subnodes.begin(), subnodes.end());
89        }
90    }
91
92    return nodes;
93}
94
95//-------------------------------------------------------------------
96
97dodo::dodoStringArray
98node::childrenNames(bool recursive)
99{
100    dodoStringArray names;
101
102    if (recursive) {
103        dodoStringArray subnames;
104        dodoStringArray::iterator x, y;
105
106        dodoArray<node>::iterator o, p;
107
108        dodoMap<dodo::string, dodoArray<node>, dodoMapStringCompare>::iterator i = nodeChildren.begin(), j = nodeChildren.end();
109        for (; i != j; ++i) {
110            o = i->second.begin();
111            p = i->second.end();
112            for (; o != p; ++o) {
113                if (!tools::misc::isInArray(names, o->name))
114                    names.push_back(o->name);
115
116                subnames = o->childrenNames(true);
117
118                x = subnames.begin();
119                y = subnames.end();
120                for (; x != y; ++x)
121                    if (!tools::misc::isInArray(names, *x))
122                        names.push_back(*x);
123            }
124        }
125    } else {
126        dodoMap<dodo::string, dodoArray<node>, dodoMapStringCompare>::iterator i = nodeChildren.begin(), j = nodeChildren.end();
127        for (; i != j; ++i)
128            names.push_back(i->first);
129    }
130
131    return names;
132}
133
134//-------------------------------------------------------------------
135
136dodo::string
137node::operator[](const dodo::string &name)
138{
139    return attributes[name];
140}
141
142//-------------------------------------------------------------------
143
144void
145node::setValue(const dodo::string &a_value,
146               bool             a_CDATA)
147{
148    CDATA = a_CDATA;
149    nodeValue = a_value;
150}
151
152//-------------------------------------------------------------------
153
154dodo::string
155node::value()
156{
157    return nodeValue;
158}
159
160//-------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.