wsdlpull  1.23
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
XmlDoc.h
Go to the documentation of this file.
1 /*
2  * wsdlpull - A C++ parser for WSDL (Web services description language)
3  * XmlNode_t and XmlDoc_t for the WsdlParser
4  * Copyright (C) 2009 Daniel Rodriguez
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20 
21 #ifndef __XMLDOC_HPP__
22 #define __XMLDOC_HPP__
23 
24 #include <ostream>
25 #include <vector>
26 #include <map>
27 #include <string>
28 
29 
30 
31 
32  class XmlNode_t {
33  public:
34  enum {
35  WS_AMOUNT = 2,
38  };
39 
40  protected:
41 
42  size_t m_depth;
43 
44  bool m_empty;
45 
46  std::string m_name;
47  std::string m_text;
48 
49  typedef std::vector< std::pair< std::string, std::string> > VectorAttributes_t;
50  typedef std::map< std::string, size_t> MapAttributes_t;
51 
54 
55  typedef std::vector< XmlNode_t *> VectorNodePtrs_t;
56  typedef std::multimap< std::string, size_t> MultiMapNodes_t;
57 
61 
64 
65 
66  public:
67  XmlNode_t( const std::string &p_name = "", size_t p_depth = 0);
68  XmlNode_t( const XmlNode_t &p_xmlNode);
69 
70  XmlNode_t &operator =( const XmlNode_t &p_xmlNode);
71 
72  virtual ~XmlNode_t();
73 
74  private:
75  void deallocateNodes( void);
76 
77  public:
78  void clear( void);
79 
80  XmlNode_t &getParent( void) const;
81  void setParent( XmlNode_t &p_parent);
82  void setParent( XmlNode_t *p_parent);
83 
84 
85  XmlNode_t &getPrev( void) const;
86  void setPrev( XmlNode_t &p_prev);
87  void setPrev( XmlNode_t *p_prev);
88 
89  XmlNode_t &getNext( void) const;
90  void setNext( XmlNode_t &p_next);
91  void setNext( XmlNode_t *p_next);
92 
93  const std::string &getName( void) const;
94  void setName( const std::string &p_name, bool p_empty = XmlNode_t::EMPTY_NODE);
95 
96  const std::string &getText( void) const;
97  void setText( const std::string &p_text);
98 
99  size_t getDepth( void) const;
100  void setDepth( size_t p_depth);
101 
102  bool isTextNode( void) const;
103  bool isRootNode( void) const;
104 
105  XmlNode_t &addNode( XmlNode_t *p_xmlNode = NULL);
106  XmlNode_t &addNode( const std::string &p_name, bool p_empty);
107 
108  void addAttribute( const std::string &p_name, const std::string &p_value);
109  bool getAttribute( const std::string &p_name, std::string &p_result) const;
110 
111  void setEmpty( bool p_empty);
112  bool empty( void) const;
113 
114  XmlNode_t *getNode( const std::string &p_name, size_t p_index = 0) const;
115 
116  void getAllChildren( XmlNode_t::VectorNodePtrs_t &p_children);
117  void findSelfOrChildren( const std::string &p_name, XmlNode_t::VectorNodePtrs_t &p_children, bool p_lazyRelativeMatch = false);
118  void findAny( const std::string &p_name, XmlNode_t::VectorNodePtrs_t &p_children);
119  void findDirectChildren( const std::string &p_name, XmlNode_t::VectorNodePtrs_t &p_children);
120 
121  bool operator ==( const XmlNode_t &p_xmlNode) const;
122 
123  friend std::ostream &operator <<( std::ostream &p_ostream, const XmlNode_t &p_xmlNode);
124 
125  };
126 
127  class XmlDoc_t {
128  protected:
129  //std::string m_version;
130  //std::string m_encoding;
131 
133 
136 
137  public:
138  XmlDoc_t( const XmlNode_t &p_xmlNode = XmlNode_t());
139 
140  void clear( void);
141 
142  void setProcessEnvAndBody( bool p_processEnvAndBody);
143  bool getProcessEnvAndBody( void) const;
144 
145  void setLazyRelativeMatch( bool p_lazyRelativeMatch);
146  bool getLazyRelativeMatch( void) const;
147 
148  XmlNode_t &setRootNode( const XmlNode_t &p_xmlNode);
149 
150  XmlNode_t &getRootNode( void);
151  const XmlNode_t &getRootNode( void) const;
152 
153  friend std::ostream &operator <<( std::ostream &p_ostream, const XmlDoc_t &p_xmlDoc);
154 
155  bool xpath( const std::string &p_xpath, std::vector< std::string> &p_results, size_t p_index = 0);
156 
157  };
158 
159 
160 #endif