startelement.h
Go to the documentation of this file.
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * As a special exception, you may use this file as part of a free
8  * software library without restriction. Specifically, if other files
9  * instantiate templates or use macros or inline functions from this
10  * file, or you compile this file and link it with other files to
11  * produce an executable, this file does not by itself cause the
12  * resulting executable to be covered by the GNU General Public
13  * License. This exception does not however invalidate any other
14  * reasons why the executable file might be covered by the GNU Library
15  * General Public License.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  */
26 #ifndef cxxtools_xml_StartElement_h
27 #define cxxtools_xml_StartElement_h
28 
29 #include <cxxtools/xml/api.h>
30 #include <cxxtools/xml/node.h>
31 #include <cxxtools/xml/namespace.h>
33 #include <cxxtools/string.h>
34 #include <list>
35 
36 namespace cxxtools {
37 
38 namespace xml {
39 
52  {
53  public:
56  { }
57 
64  Attribute(const String& name, const String& value)
65  : _name(name), _value(value)
66  { }
67 
68 
73  const String& name() const
74  { return _name; }
75 
76  String& name()
77  { return _name; }
78 
83  void setName(const String& name)
84  { _name = name; }
85 
90  const String& value() const
91  { return _value; }
92 
93  String& value()
94  { return _value; }
95 
100  void setValue(const String& value)
101  { _value = value; }
102 
103  void clear()
104  { _name.clear(); _value.clear(); }
105 
106  private:
108  String _name;
109 
111  String _value;
112  };
113 
114 
134  {
135  public:
139  { }
140 
147  StartElement(const String& name)
148  : Node(Node::StartElement),
149  _name(name)
150  { }
151 
156  StartElement* clone() const
157  {return new StartElement(*this);}
158 
159 
160  void clear()
161  {
162  _name.clear();
163  _attributes.clear();
164  }
165 
175  String& name() {return _name;}
176 
186  const String& name() const
187  {return _name;}
188 
193  void setName(const String& name)
194  {_name = name;}
195 
204  void addAttribute(const Attribute& attribute)
205  {_attributes.push_back(attribute);}
206 
217  const std::list<Attribute>& attributes() const
218  {return _attributes;}
219 
233  const String& attribute(const String& attributeName) const;
234 
244  bool hasAttribute(const String& attributeName) const;
245 
252  const NamespaceContext& namespaceContext() const
253  {return _namespaceContext;}
254 
261  void setNamespaceContext(const NamespaceContext& conText)
262  {_namespaceContext = conText;}
263 
274  const String& namespaceUri(const String& prefix) const
275  {return _namespaceContext.namespaceUri(prefix);}
276 
286  virtual bool operator==(const Node& node) const;
287 
288  private:
290  String _name;
291 
293  std::list<Attribute> _attributes;
294 
296  NamespaceContext _namespaceContext;
297  };
298 
299 }
300 
301 }
302 
303 #endif