Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 using System.Collections.Generic;
00040
00041 namespace XMLStorage
00042 {
00043
00044
00045
00046
00047
00048 public class XMLPos
00049 {
00050
00051
00052
00053
00054 public XMLPos(XMLNode root)
00055 {
00056 _root = root;
00057 _cur = root;
00058 }
00059
00060
00061
00062
00063
00064 public XMLPos(XMLPos other)
00065 {
00066 _root = other._root;
00067 _cur = other._cur;
00068
00069 }
00070
00071
00072
00073
00074
00075
00076 public XMLPos(XMLPos other, string nodeName)
00077 {
00078 _root = other._root;
00079 _cur = other._cur;
00080
00081 smartCreate(nodeName);
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 public XMLPos(XMLPos other, string nodeName, string attrName, string attrValue)
00094 {
00095 _root = other._root;
00096 _cur = other._cur;
00097
00098 smartCreate(nodeName, attrName, attrValue);
00099 }
00100
00101
00102
00103
00104
00105 public XMLNode cur()
00106 {
00107 return _cur;
00108 }
00109
00110
00111
00112
00113
00114
00115 public string get(string attrName)
00116 {
00117 return _cur.get(attrName);
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 public string get(string attrName, string def)
00127 {
00128 return _cur.get(attrName, def);
00129 }
00130
00131
00132
00133
00134
00135
00136 public void put(string attrName, string value)
00137 {
00138 _cur.put(attrName, value);
00139 }
00140
00141
00142
00143
00144
00145 public void addDown(XMLNode child)
00146 {
00147 _cur.addChild(child);
00148 goTo(child);
00149 }
00150
00151
00152
00153
00154
00155 public bool back()
00156 {
00157 if (_stack.Count > 0) {
00158 _cur = _stack.Pop();
00159 return true;
00160 } else
00161 return false;
00162 }
00163
00164
00165
00166
00167
00168 public bool goDown()
00169 {
00170 XMLNode node = _cur.getFirstChild();
00171
00172 if (node != null) {
00173 goTo(node);
00174 return true;
00175 } else
00176 return false;
00177 }
00178
00179
00180
00181
00182
00183
00184 public bool goDown(string child_name)
00185 {
00186 return goDown(child_name, 0);
00187 }
00188
00189
00190
00191
00192
00193
00194
00195 public bool goDown(string child_name, int child_idx)
00196 {
00197 XMLNode node = new XPathElement(child_name, child_idx).find(_cur);
00198
00199 if (node != null) {
00200 goTo(node);
00201 return true;
00202 } else
00203 return false;
00204 }
00205
00206
00207
00208
00209
00210
00211 public bool go(string path)
00212 {
00213 return go(new XPath(path));
00214 }
00215
00216
00217
00218
00219
00220
00221 public bool go(XPath xpath)
00222 {
00223 XMLNode node = xpath._absolute ? _root : _cur;
00224
00225 node = node.findRelative(xpath);
00226
00227 if (node != null) {
00228 goTo(node);
00229 return true;
00230 } else
00231 return false;
00232 }
00233
00234
00235
00236
00237
00238 public void create(string name)
00239 {
00240 addDown(new XMLNode(name));
00241 }
00242
00243
00244
00245
00246
00247 public void smartCreate(string child_name)
00248 {
00249 XMLNode node = new XPathElement(child_name).find(_cur);
00250
00251 if (node != null)
00252 goTo(node);
00253 else
00254 addDown(new XMLNode(child_name));
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264 public void smartCreate(string name, string attrName, string attrValue)
00265 {
00266 XMLNode node = new XPathElement(name, 0, attrName, attrValue).find(_cur);
00267
00268 if (node != null)
00269 goTo(node);
00270 else {
00271 node = new XMLNode(name);
00272 addDown(node);
00273 node.put(attrName, attrValue);
00274 }
00275 }
00276
00277
00278
00279
00280 public string getContent()
00281 {
00282 return _cur.getContent();
00283 }
00284
00285
00286
00287
00288 public void setContent(string s)
00289 {
00290 setContent(s, false);
00291 }
00292
00293
00294
00295
00296
00297 public void setContent(string s, bool cdata)
00298 {
00299 _cur.setContent(s, cdata);
00300 }
00301
00302
00303
00304
00305 public override string ToString()
00306 {
00307 return _cur.ToString();
00308 }
00309
00310 protected XMLNode _root;
00311 protected XMLNode _cur;
00312 protected Stack<XMLNode> _stack = new Stack<XMLNode>();
00313
00314
00315
00316
00317
00318 protected void goTo(XMLNode child)
00319 {
00320 _stack.Push(_cur);
00321 _cur = child;
00322 }
00323
00324
00325
00326
00327
00328
00329
00330 public void putSubattrib(string nodeName, string attrName, string value)
00331 {
00332 _cur.putSubattrib(nodeName, attrName, value);
00333 }
00334 }
00335
00336 }