![]() |
XmlNode.hGo to the documentation of this file.00001 00006 /* 00007 Copyright (C) 2008-2011 Anders Hedstrom 00008 00009 This library is made available under the terms of the GNU GPL, with 00010 the additional exemption that compiling, linking, and/or using OpenSSL 00011 is allowed. 00012 00013 If you would like to use this library in a closed-source application, 00014 a separate license agreement is available. For information about 00015 the closed-source license agreement for the C++ sockets library, 00016 please visit http://www.alhem.net/Sockets/license.html and/or 00017 email license@alhem.net. 00018 00019 This program is free software; you can redistribute it and/or 00020 modify it under the terms of the GNU General Public License 00021 as published by the Free Software Foundation; either version 2 00022 of the License, or (at your option) any later version. 00023 00024 This program is distributed in the hope that it will be useful, 00025 but WITHOUT ANY WARRANTY; without even the implied warranty of 00026 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00027 GNU General Public License for more details. 00028 00029 You should have received a copy of the GNU General Public License 00030 along with this program; if not, write to the Free Software 00031 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00032 */ 00033 #ifndef _XmlNode_H 00034 #define _XmlNode_H 00035 00036 #include "sockets-config.h" 00037 00038 #ifdef ENABLE_XML 00039 00040 #include <string> 00041 #include <libxml/xmlmemory.h> 00042 #include <libxml/parser.h> 00043 #include <map> 00044 00045 #ifdef SOCKETS_NAMESPACE 00046 namespace SOCKETS_NAMESPACE { 00047 #endif 00048 00049 class XmlDocument; 00050 00051 class XmlNode 00052 { 00053 public: 00054 XmlNode() {} 00055 XmlNode(XmlDocument&); 00056 XmlNode(XmlDocument&, const std::string& nodepath); 00057 XmlNode(const XmlNode&, const std::string& nodepath); 00058 XmlNode(xmlDocPtr, xmlNodePtr ptr); 00059 XmlNode(XmlDocument&, xmlNodePtr ptr); 00060 ~XmlNode(); 00061 00062 operator xmlNodePtr() const; 00063 XmlNode operator[](const std::string& name) const; 00064 operator std::string() const { return GetContent(); } 00065 void operator++() const; 00066 00067 xmlDocPtr GetDocument() const { return m_doc; } 00068 00069 bool Valid() const { return m_current ? true : false; } 00070 00073 xmlNodePtr GetRootElement() const; 00074 00076 std::string GetProperty(const std::string& propname) const; 00077 bool PropertyExists(const std::string& propname) const; 00078 00081 xmlNodePtr GetChildrenNode() const; 00082 00085 xmlNodePtr GetNextNode() const; 00086 00088 const std::string& GetNodeName() const; 00090 const std::string& GetContent() const; 00091 00100 void SetCurrent(xmlNodePtr p) const { m_current = p; } 00101 00103 xmlNsPtr GetNodeNs() const; 00105 const std::string& GetNodeNsPrefix() const; 00107 const std::string& GetNodeNsHref() const; 00108 00111 xmlNodePtr GetFirstElement(const std::string& name) const; 00112 00115 xmlNodePtr GetFirstElement(xmlNodePtr parent,const std::string& name) const; 00116 00119 xmlNodePtr GetNextElement(xmlNodePtr node,const std::string& name) const; 00120 00122 bool Exists(const std::string& name) const; 00123 00125 std::map<std::string, std::string> GetNsMap() const; 00126 00128 std::map<std::string, std::string> GetNsMapRe() const; 00129 00130 const std::string FindProperty(const std::string& propname, bool climb = false) const; 00131 00132 private: 00133 xmlDocPtr m_doc; 00134 mutable xmlNodePtr m_current; 00135 mutable std::string m_current_name; 00136 mutable std::string m_ns_prefix; 00137 mutable std::string m_ns_href; 00138 mutable std::string m_content; 00139 mutable std::string m_lookup_name; 00140 }; 00141 00142 00143 #ifdef SOCKETS_NAMESPACE 00144 } 00145 #endif 00146 00147 #endif // ENABLE_XML 00148 #endif // _XmlNode_H |