MI - Fimex
XMLDoc.h
Go to the documentation of this file.
1 /*
2  * Fimex
3  *
4  * (C) Copyright 2008, met.no
5  *
6  * Project Info: https://wiki.met.no/fimex/start
7  *
8  * This library is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21  * USA.
22  */
23 
24 #ifndef XMLDOC_H_
25 #define XMLDOC_H_
26 #include <boost/utility.hpp>
27 #include <boost/shared_ptr.hpp>
28 #include <string>
29 #include "fimex/CDMException.h"
30 
31 //forward decl;
32 struct _xmlDoc;
33 struct _xmlXPathContext;
34 struct _xmlXPathObject;
35 struct _xmlNode;
36 typedef struct _xmlDoc xmlDoc;
37 typedef struct _xmlNode xmlNode;
38 typedef struct _xmlXPathContext xmlXPathContext;
40 typedef struct _xmlXPathObject xmlXPathObject;
41 
42 namespace MetNoFimex
43 {
44 
45 typedef boost::shared_ptr<xmlXPathObject> XPathObjPtr;
46 
53 class XMLDoc : boost::noncopyable
54 {
55 public:
62  explicit XMLDoc(const std::string& filename);
63  virtual ~XMLDoc();
72  XPathObjPtr getXPathObject(const std::string& xpath, xmlNodePtr node = 0) const;
80  void registerNamespace(const std::string& prefix, const std::string& uri);
81 
89  std::string toString(const xmlNodePtr node);
90 
91  static boost::shared_ptr<XMLDoc> fromFile(const std::string& filename);
92  static boost::shared_ptr<XMLDoc> fromString(const std::string& buffer, const std::string& url = "");
93  static boost::shared_ptr<XMLDoc> fromURL(const std::string& url);
94 
95 private:
99  explicit XMLDoc();
100  void init();
101  void setDoc(xmlDoc* pdoc);
102  void setXPathCtx(xmlDoc* pdoc);
106  xmlDoc* doc;
107  xmlXPathContext* xpathCtx;
108  void cleanup();
109 };
110 
116 std::string getXmlProp(const xmlNodePtr node, const std::string& attrName);
117 
123 std::string getXmlName(const xmlNodePtr node);
132 
133 
134 }
135 
136 #endif /*XMLDOC_H_*/
std::string getXmlName(const xmlNodePtr node)
basic_string< char > string
struct _xmlXPathObject xmlXPathObject
Definition: XMLDoc.h:40
std::string getXmlProp(const xmlNodePtr node, const std::string &attrName)
struct _xmlNode xmlNode
Definition: XMLDoc.h:37
std::string getXmlContent(const xmlNodePtr node)
get all text-contents of the node or underlying nodes
static boost::shared_ptr< XMLDoc > fromFile(const std::string &filename)
xmlNode * xmlNodePtr
Definition: XMLDoc.h:39
Definition: C_CDMReader.h:35
struct _xmlDoc xmlDoc
Definition: XMLDoc.h:36
void registerNamespace(const std::string &prefix, const std::string &uri)
register a namespace for later xpath
struct _xmlXPathContext xmlXPathContext
Definition: XMLDoc.h:38
std::string toString(const xmlNodePtr node)
XPathObjPtr getXPathObject(const std::string &xpath, xmlNodePtr node=0) const
Definition: XMLDoc.h:53
static boost::shared_ptr< XMLDoc > fromURL(const std::string &url)
boost::shared_ptr< xmlXPathObject > XPathObjPtr
Definition: XMLDoc.h:45
static boost::shared_ptr< XMLDoc > fromString(const std::string &buffer, const std::string &url="")