nidas  v1.2-1520
XDOM.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2004, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
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 General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 
27 #ifndef NIDAS_CORE_XDOM_H
28 #define NIDAS_CORE_XDOM_H
29 
30 #include "XMLStringConverter.h"
31 
32 #include <xercesc/dom/DOMElement.hpp>
33 #include <xercesc/dom/DOMAttr.hpp>
34 #include <xercesc/dom/DOMTypeInfo.hpp>
35 
36 #include <string>
37 #include <map>
38 
39 namespace nidas { namespace core {
40 
45 class XDOMElement {
46 public:
47  XDOMElement(const xercesc::DOMElement*e) :
50 #if XERCES_VERSION_MAJOR < 3
51  _nodetype( e->getTypeInfo() ? (std::string)XMLStringConverter(e->getTypeInfo()->getName()) : "")
52 #else
53  _nodetype( e->getSchemaTypeInfo() ? (std::string)XMLStringConverter(e->getSchemaTypeInfo()->getTypeName()) : "")
54 #endif
55  {
56  }
57 
58  XDOMElement(xercesc::DOMElement*e) :
61  {
62  }
63 
68  const std::string& getAttributeValue(const std::string& aname) {
69  std::map<std::string,std::string>::const_iterator ai = _attrs.find(aname);
70  if (ai == _attrs.end()) {
71  XMLStringConverter cname(aname.c_str());
72 
73  // returns empty string if attribute does not have a
74  // specified or default value.
75  XMLStringConverter aval(_elemConst->getAttribute((const XMLCh*)cname));
76 
77  std::pair<const std::string,const std::string>
78  p(aname,aval);
79  _attrs.insert(p);
80  ai = _attrs.find(aname);
81  }
82  return ai->second;
83  }
84  void setAttributeValue(const std::string& name,const std::string& val)
85  {
86  XMLStringConverter aname(name);
87  XMLStringConverter aval(val);
88  if (_elemNonConst)
89  _elemNonConst->setAttribute((const XMLCh*)aname,(const XMLCh*)aval);
90  _attrs[name] = val;
91  }
92  const std::string& getNodeName() const { return _nodename; }
93 
94  const std::string& getNodeType() const {return _nodetype; }
95 
96  const xercesc::DOMElement* getElement() const { return _elemConst; }
97 
98 private:
99  const xercesc::DOMElement* _elemConst;
100 
101  xercesc::DOMElement* _elemNonConst;
102 
103  std::map<std::string,std::string> _attrs;
104 
105  std::string _nodename;
106 
107  std::string _nodetype;
108 
110  XDOMElement(const XDOMElement&);
111 
114 };
115 
120 class XDOMAttr {
121 public:
122  XDOMAttr(const xercesc::DOMAttr*a) :
123  _attr(a),
126  {
127  }
128  const std::string& getName() const { return _name; }
129  const std::string& getValue() const { return _value; }
130 protected:
131  const xercesc::DOMAttr* _attr;
132  std::string _name;
133  std::string _value;
134 
135 private:
137  XDOMAttr(const XDOMAttr&);
138 
140  XDOMAttr& operator=(const XDOMAttr&);
141 };
142 
143 }} // namespace nidas namespace core
144 
145 #endif
Class providing convienence methods to access the string attributes of a DOMAttr. ...
Definition: XDOM.h:120
XDOMElement(xercesc::DOMElement *e)
Definition: XDOM.h:58
Wrapper class providing convienence methods to access the string attributes of a DOMElement.
Definition: XDOM.h:45
XDOMElement & operator=(const XDOMElement &)
No assignment.
const std::string & getAttributeValue(const std::string &aname)
Definition: XDOM.h:68
Class providing conversions between string and XMLCh* using the Xerces-c transcode and release method...
Definition: XMLStringConverter.h:38
std::string _value
Definition: XDOM.h:133
std::map< std::string, std::string > _attrs
Definition: XDOM.h:103
const std::string & getNodeName() const
Definition: XDOM.h:92
const std::string & getNodeType() const
Definition: XDOM.h:94
void setAttributeValue(const std::string &name, const std::string &val)
Definition: XDOM.h:84
std::string _nodetype
Definition: XDOM.h:107
std::string _name
Definition: XDOM.h:132
XDOMAttr(const xercesc::DOMAttr *a)
Definition: XDOM.h:122
std::string _nodename
Definition: XDOM.h:105
const std::string & getValue() const
Definition: XDOM.h:129
XDOMElement(const xercesc::DOMElement *e)
Definition: XDOM.h:47
const xercesc::DOMElement * _elemConst
Definition: XDOM.h:99
xercesc::DOMElement * _elemNonConst
Definition: XDOM.h:101
const std::string & getName() const
Definition: XDOM.h:128
const xercesc::DOMElement * getElement() const
Definition: XDOM.h:96
if(!fp)
Definition: sing.cc:929
const xercesc::DOMAttr * _attr
Definition: XDOM.h:131
XDOMAttr & operator=(const XDOMAttr &)
No assignment.