File: XMLTree_8hpp-source.html

package info (click to toggle)
sp-gxmlcpp 1.0.20040603-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,596 kB
  • ctags: 266
  • sloc: sh: 7,483; cpp: 1,629; makefile: 119
file content (172 lines) | stat: -rw-r--r-- 13,487 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>XMLTree.hpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="examples.html">Examples</a> &nbsp; </center>
<hr><h1>XMLTree.hpp</h1><a href="XMLTree_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/*</font>
00002 <font class="comment"> * (C) Copyright 2002, Schlund+Partner AG</font>
00003 <font class="comment"> *</font>
00004 <font class="comment"> * This library is free software; you can redistribute it and/or</font>
00005 <font class="comment"> * modify it under the terms of the GNU Lesser General Public</font>
00006 <font class="comment"> * License as published by the Free Software Foundation; either</font>
00007 <font class="comment"> * version 2.1 of the License, or (at your option) any later version.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This library is distributed in the hope that it will be useful,</font>
00010 <font class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00011 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</font>
00012 <font class="comment"> * Lesser General Public License for more details.</font>
00013 <font class="comment"> *</font>
00014 <font class="comment"> * You should have received a copy of the GNU Lesser General Public</font>
00015 <font class="comment"> * License along with this library; if not, write to the Free Software</font>
00016 <font class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</font>
00017 <font class="comment">*/</font>
00018 
00019 <font class="preprocessor">#ifndef SP_GXML_XMLTREE_HPP</font>
00020 <font class="preprocessor"></font><font class="preprocessor">#define SP_GXML_XMLTREE_HPP</font>
00021 <font class="preprocessor"></font>
00034 <font class="comment">// STDC++</font>
00035 <font class="preprocessor">#include &lt;string&gt;</font>
00036 <font class="preprocessor">#include &lt;memory&gt;</font>
00037 <font class="preprocessor">#include &lt;fstream&gt;</font>
00038 
00039 <font class="comment">// Local</font>
00040 <font class="preprocessor">#include &lt;<a class="code" href="XMLNodeSet_8hpp.html">sp-gxmlcpp/XMLNodeSet.hpp</a>&gt;</font>
00041 <font class="preprocessor">#include &lt;<a class="code" href="XMLException_8hpp.html">sp-gxmlcpp/XMLException.hpp</a>&gt;</font>
00042 
00043 
00044 <font class="comment">/* NOTES</font>
00045 <font class="comment">   o xmlChar is one byte.</font>
00046 <font class="comment">   o "xmlChar" is compatible to "char"; xmlChar * Strings are always 0-terminated; (xmlChar *) is compatible to (char *)/string.c_str()</font>
00047 <font class="comment">   o Simply using char *, string makes us still compatible with: UTF-8, ASCII, ISO-8859-*, ... (basically, all "up-to-8-Bits-Encodings").</font>
00048 <font class="comment">   o UCS-2/UCS-4 encodings might be a problem.</font>
00049 <font class="comment"></font>
00050 <font class="comment">   UNICODE  ISO 10646    All characters of the planet listed and labeled....</font>
00051 <font class="comment"></font>
00052 <font class="comment">   UCS-2: 16-Bit Encoding of UNICODE.</font>
00053 <font class="comment">   UCS-4: 32-Bit Encoding of UNICODE.</font>
00054 <font class="comment">   UTF-8: 8-Bit Encoding of UNICODE. All todays ISO-8859-1 texts qualify as UTF-8. This is what UNIXses will do.</font>
00055 <font class="comment">*/</font>
00056 
00057 <font class="keyword">namespace </font>SP
00058 {
00059 <font class="keyword">namespace </font>GXML
00060 {
00061 
00062 <font class="comment">//</font>
00063 <font class="comment">// XMLTree</font>
00064 <font class="comment">//</font>
00065 <font class="keyword">class </font>XMLTree
00066 {
00067         <font class="comment">/* enum Exceptions</font>
00068 <font class="comment">                 {</font>
00069 <font class="comment">                 PARSE_ERR=1,           // XML could not be parsed</font>
00070 <font class="comment">                 CONTEXT_ERR,           // Could not create (XPath) context for Tree</font>
00071 <font class="comment">                 NO_NODE_FROM_PATH_ERR, // Could not find node from specified path</font>
00072 <font class="comment">                 NODE_CREATION_ERR,     // Could not create a node</font>
00073 <font class="comment">                 NODE_ADDING_ERR,       // Could not add a creted node</font>
00074 <font class="comment">                 TREE_INVALID_ERR       // Could not add a creted node</font>
00075 <font class="comment">                 }; */</font>
00076 <font class="keyword">public</font>:
00077         <font class="comment">// Creators for char-Buffer, C++ string, ifstream</font>
00078         XMLTree(<font class="keyword">const</font> xmlDocPtr doc);
00079         XMLTree(<font class="keyword">const</font> <font class="keywordtype">char</font> * xmlBuffer, <font class="keywordtype">int</font> size=-1);  <font class="comment">// if size &lt; 0, xmlBuffer must be a valid C-String!</font>
00080         XMLTree(<font class="keyword">const</font> std::string &amp; xmlString);
00081         XMLTree(std::ifstream &amp; xmlStream);
00082         XMLTree(std::istream &amp; xmlStream);
00083 
00084         ~XMLTree();
00085 
00086         std::string getString( <font class="keyword">const</font> std::string&amp; xpath );
00087         <font class="keywordtype">bool</font> getBool( <font class="keyword">const</font> std::string&amp; xpath );
00088         <font class="keywordtype">double</font> getFloat( <font class="keyword">const</font> std::string&amp; xpath );
00089 
00090         <font class="comment">// REMARK : the returned XMLNodeSet has to be freed by the calling method</font>
00091         std::auto_ptr&lt;XMLNodeSet&gt; getNodeSet( <font class="keyword">const</font> std::string&amp; xpath );
00092 
00094         <font class="comment">// Get internal libxml2 Pointers</font>
00095         <font class="comment">//  - this will allow us to call libxml2-Functions on the tree directly.</font>
00096         <font class="comment">//    (i.e., helling the abstraction for speed)</font>
00097         xmlDocPtr getDocPtr() <font class="keyword">const</font>;
00098         xmlXPathContextPtr getXPathContextPtr() <font class="keyword">const</font>;
00099 
00101         <font class="comment">// "Get Methods" based on "XPath"; paths are XPath Expressions;</font>
00102         <font class="comment">// all paths can be given an optional position</font>
00103         <font class="comment">//  - Methods delivering (xmlChar *) point into the tree</font>
00104         <font class="comment">//  - Methods delivering (std::string, int) obviously copy from tree</font>
00105         <font class="comment">//  - getValue-Methods will deliver the contents of the first child only</font>
00106         <font class="comment">//    e.g.: getValue("/req/X", 0) on</font>
00107         <font class="comment">// "&lt;req&gt;&lt;X&gt;a b c&lt;subtag&gt;def&lt;/subtag&gt;&lt;/X&gt;&lt;/req&gt;" returns: "a b c" only.</font>
00108 
00109         <font class="comment">// "libxml2"-Functions. Do not use if you want to be abstract.</font>
00110         xmlChar * getXmlCharValue(<font class="keyword">const</font> xmlChar * path) <font class="keyword">const</font>;
00111         xmlChar * getXmlCharValue(<font class="keyword">const</font> std::string &amp; path) <font class="keyword">const</font>;
00112 
00113         <font class="comment">// "C++"-functions</font>
00114         <font class="keywordtype">char</font> * getAddrValue(<font class="keyword">const</font> std::string &amp; path) <font class="keyword">const</font>;
00115         std::string getValue(<font class="keyword">const</font> std::string &amp; path) <font class="keyword">const</font>;
00116 
00117         <font class="keywordtype">char</font> * getAddrName(<font class="keyword">const</font> std::string &amp; path) <font class="keyword">const</font>;
00118         std::string getName(<font class="keyword">const</font> std::string &amp; path) <font class="keyword">const</font>;
00119 
00120         <font class="keywordtype">void</font> setValue(<font class="keyword">const</font> std::string &amp; path, <font class="keywordtype">char</font> * value);
00121         <font class="keywordtype">void</font> setValue(<font class="keyword">const</font> std::string &amp; path, <font class="keyword">const</font> std::string &amp; value);
00122 
00123         <font class="comment">/* Obsoleted by XMLDump</font>
00124 <font class="comment">        // getTreeAsString=recursive: This gets the complete contents of the tag</font>
00125 <font class="comment">        //  e.g.: getTreeAsString("/req/X", 0) on "&lt;req&gt;&lt;X&gt;a b c&lt;subtag&gt;def&lt;/subtag&gt;</font>
00126 <font class="comment">        // &lt;/X&gt;&lt;/req&gt;" returns: "&lt;X&gt;a b c&lt;subtag&gt;def&lt;/subtag&gt;&lt;/X&gt;".</font>
00127 <font class="comment">        std::string getTreeAsString(const std::string &amp; path) const;</font>
00128 <font class="comment">        */</font>
00129 
00130         <font class="keywordtype">int</font> getCount(<font class="keyword">const</font> xmlChar * path) <font class="keyword">const</font>;
00131         <font class="keywordtype">int</font> getCount(<font class="keyword">const</font> <font class="keywordtype">char</font> * path) <font class="keyword">const</font>;
00132         <font class="keywordtype">int</font> getCount(<font class="keyword">const</font> std::string &amp; path) <font class="keyword">const</font>;
00133 
00135         <font class="comment">// "Modifying Methods" based on "XPath"; paths are XPath Expressions</font>
00136         <font class="comment">//  - Methods delivering (xmlChar *) point into the tree</font>
00137         <font class="comment">//  - Methods delivering (std::string, int) copy from tree</font>
00138         <font class="keywordtype">void</font> delTag(<font class="keyword">const</font> std::string &amp; path);
00139         <font class="keywordtype">void</font> addTag(<font class="keyword">const</font> std::string &amp; path, <font class="keyword">const</font> std::string &amp; name, <font class="keyword">const</font> std::string &amp; content);
00140 
00148         <font class="keywordtype">void</font> addSiblingTag(<font class="keyword">const</font> std::string &amp; path, <font class="keyword">const</font> std::string &amp; name, <font class="keyword">const</font> std::string &amp; content);
00149 
00157         std::string getSiblingXML( <font class="keyword">const</font> std::string&amp; path = <font class="stringliteral">"/*"</font> );
00158 
00159         <font class="comment">// addTree: Adds the whole tree as new child for node</font>
00160         <font class="comment">// This will COPY. No other method available from libxml2. We cannot mix trees.</font>
00161         <font class="keywordtype">void</font> addTree(<font class="keyword">const</font> std::string &amp; path, XMLTree * xmlTree);
00162         <font class="keywordtype">void</font> addXML(<font class="keyword">const</font> std::string &amp; path, <font class="keyword">const</font> std::string &amp; xml);
00163 
00164         std::string getXML(<font class="keyword">const</font> std::string &amp; path=<font class="stringliteral">"/"</font>) <font class="keyword">const</font>;
00165 
00166         std::auto_ptr&lt;XMLTree&gt; getTree(<font class="keyword">const</font> std::string &amp;path=<font class="stringliteral">"/"</font>);
00167 
00169         <font class="comment">// Utility functions</font>
00170         <font class="comment">//</font>
00171         <font class="comment">// Node from Path</font>
00172         <font class="keyword">static</font> xmlNodePtr nodeFromPath(xmlXPathContextPtr context, <font class="keyword">const</font> xmlChar * path);
00173         <font class="comment">// Node from Path</font>
00174         <font class="keyword">static</font> xmlNodePtr nodeFromPath(xmlXPathContextPtr context, <font class="keyword">const</font> std::string &amp; path);
00175 
00176 <font class="keyword">private</font>:
00177         xmlDocPtr tree_;
00178         xmlXPathContextPtr context_;
00179 
00180         <font class="comment">// Constructor helper function</font>
00181         <font class="keywordtype">void</font> genTree(<font class="keyword">const</font> <font class="keywordtype">char</font> * xmlBuffer, <font class="keywordtype">int</font> size=-1);
00182 
00183         xmlXPathObjectPtr createXPathObject( <font class="keyword">const</font> std::string&amp; xpath );
00184         <font class="keywordtype">void</font> destroyXPathObject( xmlXPathObjectPtr obj );
00185 };
00186 
00187 }}
00188 <font class="preprocessor">#endif</font>
</pre></div><hr><address align="right"><small>Generated on Thu Jun 3 19:20:12 2004 for sp-gxmlcpp by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>