Logo
~Sockets~
~Examples~
~Contact~


BaseXMLFile Class Reference

#include <BaseXMLFile.h>

Inheritance diagram for BaseXMLFile:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 BaseXMLFile (const std::string &filename, const std::string &verify_ns="", const std::string &verify_root="")
 ~BaseXMLFile ()
xmlDocPtr GetDocument ()
xmlNodePtr GetRootElement ()
std::string GetProperty (const std::string &)
xmlNodePtr GetChildrenNode ()
xmlNodePtr GetNextNode ()
const std::string & GetNodeName ()
void SetCurrent (xmlNodePtr p)
xmlNsPtr GetNodeNs ()
const std::string & GetNodeNsPrefix ()
const std::string & GetNodeNsHref ()
xmlNodePtr GetFirstElement (const std::string &)
xmlNodePtr GetFirstElement (xmlNodePtr, const std::string &)
xmlNodePtr GetNextElement (xmlNodePtr, const std::string &)

Private Attributes

xmlDocPtr m_doc
xmlNodePtr m_current
std::string m_current_name
std::string m_ns_prefix
std::string m_ns_href

Detailed Description

File ......... BaseXMLFile.h Published .... 2004-07-13 Author ....... grymse@alhem.net

Definition at line 31 of file BaseXMLFile.h.


Constructor & Destructor Documentation

BaseXMLFile::BaseXMLFile ( const std::string &  filename,
const std::string &  verify_ns = "",
const std::string &  verify_root = "" 
)

File ......... BaseXMLFile.cpp Published .... 2004-07-13 Author ....... grymse@alhem.net

Definition at line 30 of file BaseXMLFile.cpp.

References m_doc.

00031 : m_doc(NULL)
00032 ,m_current(NULL)
00033 {
00034         xmlNodePtr cur;
00035         xmlNsPtr ns;
00036 
00037         if (!(m_doc = xmlParseFile(filename.c_str() )))
00038         {
00039                 fprintf(stderr,"xmlParseFile('%s') failed\n",filename.c_str());
00040                 return;
00041         }
00042 
00043         if (!(cur = xmlDocGetRootElement(m_doc)))
00044         {
00045                 fprintf(stderr, "Empty document\n");
00046                 xmlFreeDoc(m_doc);
00047                 m_doc = NULL;
00048                 return;
00049         }
00050 
00051         if (!verify_ns.size())
00052         {
00053                 return; // we're ok
00054         }
00055         if (!(ns = xmlSearchNsByHref(m_doc, cur, (const xmlChar *) verify_ns.c_str() )))
00056         {
00057                 fprintf(stderr, "Document namespace != '%s'\n", verify_ns.c_str());
00058                 xmlFreeDoc(m_doc);
00059                 m_doc = NULL;
00060                 return;
00061         }
00062 
00063         if (!verify_root.size())
00064         {
00065                 return;
00066         }
00067         if (xmlStrcmp(cur -> name, (const xmlChar *) verify_root.c_str() ))
00068         {
00069                 fprintf(stderr, "Document root != '%s'\n",verify_root.c_str());
00070                 xmlFreeDoc(m_doc);
00071                 m_doc = NULL;
00072                 return;
00073         }
00074 
00075 }

BaseXMLFile::~BaseXMLFile (  ) 

Definition at line 78 of file BaseXMLFile.cpp.

References m_doc.

00079 {
00080         if (m_doc)
00081         {
00082                 xmlFreeDoc(m_doc);
00083         }
00084 }


Member Function Documentation

xmlDocPtr BaseXMLFile::GetDocument (  )  [inline]

Definition at line 37 of file BaseXMLFile.h.

References m_doc.

00037 { return m_doc; }

xmlNodePtr BaseXMLFile::GetRootElement (  ) 

Definition at line 87 of file BaseXMLFile.cpp.

References m_current, and m_doc.

Referenced by ServerHandler::GetBoolean(), GetFirstElement(), ServerHandler::GetInt(), and ServerHandler::GetString().

00088 {
00089         m_current = m_doc ? xmlDocGetRootElement(m_doc) : NULL;
00090         return m_current;
00091 }

std::string BaseXMLFile::GetProperty ( const std::string &   ) 

Definition at line 94 of file BaseXMLFile.cpp.

References m_current.

Referenced by ServerHandler::GetBoolean(), ServerHandler::GetInt(), and ServerHandler::GetString().

00095 {
00096         xmlChar *p = m_current ? xmlGetProp(m_current, (const xmlChar *) name.c_str() ) : NULL;
00097         if (!p)
00098         {
00099                 return "";
00100         }
00101         std::string str = (char *)p;
00102         xmlFree(p);
00103         return str;
00104 }

xmlNodePtr BaseXMLFile::GetChildrenNode (  ) 

Definition at line 107 of file BaseXMLFile.cpp.

References m_current.

Referenced by GetFirstElement().

00108 {
00109         m_current = m_current ? m_current -> xmlChildrenNode : NULL;
00110         return m_current;
00111 }

xmlNodePtr BaseXMLFile::GetNextNode (  ) 

Definition at line 114 of file BaseXMLFile.cpp.

References m_current.

Referenced by GetFirstElement(), and GetNextElement().

00115 {
00116         do
00117         {
00118                 m_current = m_current ? m_current -> next : NULL;
00119         } while (m_current && xmlIsBlankNode( m_current ));
00120         return m_current;
00121 }

const std::string & BaseXMLFile::GetNodeName (  ) 

Definition at line 124 of file BaseXMLFile.cpp.

References m_current, and m_current_name.

Referenced by GetFirstElement(), and GetNextElement().

00125 {
00126         if (m_current)
00127         {
00128                 m_current_name = (char *)m_current -> name;
00129         }
00130         else
00131         {
00132                 m_current_name = "";
00133         }
00134         return m_current_name;
00135 }

void BaseXMLFile::SetCurrent ( xmlNodePtr  p  )  [inline]

xmlNsPtr BaseXMLFile::GetNodeNs (  ) 

Definition at line 138 of file BaseXMLFile.cpp.

References m_current.

00139 {
00140         if (m_current)
00141                 return m_current -> ns;
00142         return NULL;
00143 }

const std::string & BaseXMLFile::GetNodeNsPrefix (  ) 

Definition at line 146 of file BaseXMLFile.cpp.

References m_current, and m_ns_prefix.

00147 {
00148         if (m_current && m_current -> ns && m_current -> ns -> prefix)
00149         {
00150                 m_ns_prefix = (char *)m_current -> ns -> prefix;
00151         }
00152         else
00153         {
00154                 m_ns_prefix = "";
00155         }
00156         return m_ns_prefix;
00157 }

const std::string & BaseXMLFile::GetNodeNsHref (  ) 

Definition at line 160 of file BaseXMLFile.cpp.

References m_current, and m_ns_href.

00161 {
00162         if (m_current && m_current -> ns && m_current -> ns -> href)
00163         {
00164                 m_ns_href = (char *)m_current -> ns -> href;
00165         }
00166         else
00167         {
00168                 m_ns_href = "";
00169         }
00170         return m_ns_href;
00171 }

xmlNodePtr BaseXMLFile::GetFirstElement ( const std::string &   ) 

Definition at line 174 of file BaseXMLFile.cpp.

References GetChildrenNode(), GetNextNode(), GetNodeName(), and GetRootElement().

Referenced by Configuration::Find().

00175 {
00176         GetRootElement();
00177         xmlNodePtr p = GetChildrenNode();
00178         while (p)
00179         {
00180                 if (name == GetNodeName())
00181                 {
00182                         return p;
00183                 }
00184                 p = GetNextNode();
00185         }
00186         return NULL;
00187 }

xmlNodePtr BaseXMLFile::GetFirstElement ( xmlNodePtr  ,
const std::string &   
)

Definition at line 190 of file BaseXMLFile.cpp.

References GetChildrenNode(), GetNextNode(), GetNodeName(), and SetCurrent().

00191 {
00192         SetCurrent(base);
00193         xmlNodePtr p = GetChildrenNode();
00194         while (p)
00195         {
00196                 if (name == GetNodeName())
00197                 {
00198                         return p;
00199                 }
00200                 p = GetNextNode();
00201         }
00202         return NULL;
00203 }

xmlNodePtr BaseXMLFile::GetNextElement ( xmlNodePtr  ,
const std::string &   
)

Definition at line 206 of file BaseXMLFile.cpp.

References GetNextNode(), GetNodeName(), and SetCurrent().

00207 {
00208         SetCurrent(p);
00209         p = GetNextNode();
00210         while (p)
00211         {
00212                 if (name == GetNodeName())
00213                 {
00214                         return p;
00215                 }
00216                 p = GetNextNode();
00217         }
00218         return NULL;
00219 }


Member Data Documentation

xmlDocPtr BaseXMLFile::m_doc [private]

Definition at line 53 of file BaseXMLFile.h.

Referenced by BaseXMLFile(), GetDocument(), GetRootElement(), and ~BaseXMLFile().

std::string BaseXMLFile::m_current_name [private]

Definition at line 55 of file BaseXMLFile.h.

Referenced by GetNodeName().

std::string BaseXMLFile::m_ns_prefix [private]

Definition at line 56 of file BaseXMLFile.h.

Referenced by GetNodeNsPrefix().

std::string BaseXMLFile::m_ns_href [private]

Definition at line 57 of file BaseXMLFile.h.

Referenced by GetNodeNsHref().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4