XPathNavigator.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. //
  2. // System.Xml.XPath.XPathNavigator
  3. //
  4. // Author:
  5. // Jason Diamond ([email protected])
  6. // Atsushi Enomoto ([email protected])
  7. //
  8. // (C) 2002 Jason Diamond http://injektilo.org/
  9. // (C) 2004 Novell Inc.
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.Collections;
  33. using System.IO;
  34. using System.Xml;
  35. using System.Xml.Schema;
  36. using Mono.Xml.XPath;
  37. #if NET_2_0
  38. using NSResolver = System.Xml.IXmlNamespaceResolver;
  39. #else
  40. using NSResolver = System.Xml.XmlNamespaceManager;
  41. #endif
  42. namespace System.Xml.XPath
  43. {
  44. #if NET_2_0
  45. public abstract class XPathNavigator : XPathItem,
  46. ICloneable, IXPathNavigable, IXmlNamespaceResolver
  47. #else
  48. public abstract class XPathNavigator : ICloneable
  49. #endif
  50. {
  51. #region Constructor
  52. protected XPathNavigator ()
  53. {
  54. }
  55. #endregion
  56. #region Properties
  57. public abstract string BaseURI { get; }
  58. #if NET_2_0
  59. public virtual bool HasAttributes {
  60. get { return Clone ().MoveToFirstAttribute (); }
  61. }
  62. public virtual bool HasChildren {
  63. get { return Clone ().MoveToFirstChild (); }
  64. }
  65. #else
  66. public abstract bool HasAttributes { get; }
  67. public abstract bool HasChildren { get; }
  68. #endif
  69. public abstract bool IsEmptyElement { get; }
  70. public abstract string LocalName { get; }
  71. public abstract string Name { get; }
  72. public abstract string NamespaceURI { get; }
  73. public abstract XmlNameTable NameTable { get; }
  74. public abstract XPathNodeType NodeType { get; }
  75. public abstract string Prefix { get; }
  76. #if NET_2_0
  77. public virtual string XmlLang {
  78. get {
  79. XPathNavigator nav = Clone ();
  80. switch (nav.NodeType) {
  81. case XPathNodeType.Attribute:
  82. case XPathNodeType.Namespace:
  83. nav.MoveToParent ();
  84. break;
  85. }
  86. do {
  87. if (nav.MoveToAttribute ("lang", "http://www.w3.org/XML/1998/namespace"))
  88. return nav.Value;
  89. } while (nav.MoveToParent ());
  90. return String.Empty;
  91. }
  92. }
  93. #else
  94. public abstract string Value { get; }
  95. public abstract string XmlLang { get; }
  96. #endif
  97. int Depth
  98. {
  99. get
  100. {
  101. int cLevels = 0;
  102. XPathNavigator nav = Clone ();
  103. while (nav.MoveToParent ())
  104. cLevels ++;
  105. return cLevels;
  106. }
  107. }
  108. #endregion
  109. #region Methods
  110. public abstract XPathNavigator Clone ();
  111. public virtual XmlNodeOrder ComparePosition (XPathNavigator nav)
  112. {
  113. if (IsSamePosition (nav))
  114. return XmlNodeOrder.Same;
  115. XPathNavigator nav1 = Clone ();
  116. XPathNavigator nav2 = nav.Clone ();
  117. int nDepth1 = nav1.Depth;
  118. int nDepth2 = nav2.Depth;
  119. if (nDepth1 > nDepth2)
  120. {
  121. while (nDepth1 > nDepth2)
  122. {
  123. if (!nav1.MoveToParent ())
  124. break;
  125. nDepth1 --;
  126. }
  127. if (nav1.IsSamePosition (nav2))
  128. return XmlNodeOrder.After;
  129. }
  130. else if (nDepth1 < nDepth2)
  131. {
  132. while (nDepth1 < nDepth2)
  133. {
  134. if (!nav2.MoveToParent ())
  135. break;
  136. nDepth2 --;
  137. }
  138. if (nav1.IsSamePosition (nav2))
  139. return XmlNodeOrder.Before;
  140. }
  141. XPathNavigator parent1 = nav1.Clone ();
  142. XPathNavigator parent2 = nav2.Clone ();
  143. while (parent1.MoveToParent () && parent2.MoveToParent ())
  144. {
  145. if (parent1.IsSamePosition (parent2))
  146. {
  147. // the ordering is namespace, attribute, children
  148. // assume that nav1 is before nav2, find counter-example
  149. if (nav1.NodeType == XPathNodeType.Namespace)
  150. {
  151. if (nav2.NodeType == XPathNodeType.Namespace)
  152. {
  153. // match namespaces
  154. while (nav2.MoveToNextNamespace ())
  155. if (nav2.IsSamePosition (nav1))
  156. return XmlNodeOrder.After;
  157. }
  158. }
  159. else if (nav1.NodeType == XPathNodeType.Attribute)
  160. {
  161. if (nav2.NodeType == XPathNodeType.Namespace)
  162. return XmlNodeOrder.After;
  163. else if (nav2.NodeType == XPathNodeType.Attribute)
  164. {
  165. // match attributes
  166. while (nav2.MoveToNextAttribute ())
  167. if (nav2.IsSamePosition (nav1))
  168. return XmlNodeOrder.After;
  169. }
  170. }
  171. else
  172. {
  173. switch (nav2.NodeType) {
  174. case XPathNodeType.Namespace:
  175. case XPathNodeType.Attribute:
  176. return XmlNodeOrder.After;
  177. }
  178. // match children
  179. while (nav2.MoveToNext ())
  180. if (nav2.IsSamePosition (nav1))
  181. return XmlNodeOrder.After;
  182. }
  183. return XmlNodeOrder.Before;
  184. }
  185. nav1.MoveToParent ();
  186. nav2.MoveToParent ();
  187. }
  188. return XmlNodeOrder.Unknown;
  189. }
  190. public virtual XPathExpression Compile (string xpath)
  191. {
  192. XPathParser parser = new XPathParser ();
  193. return new CompiledExpression (parser.Compile (xpath));
  194. }
  195. internal virtual XPathExpression Compile (string xpath, System.Xml.Xsl.IStaticXsltContext ctx)
  196. {
  197. XPathParser parser = new XPathParser (ctx);
  198. return new CompiledExpression (parser.Compile (xpath));
  199. }
  200. public virtual object Evaluate (string xpath)
  201. {
  202. return Evaluate (Compile (xpath));
  203. }
  204. public virtual object Evaluate (XPathExpression expr)
  205. {
  206. return Evaluate (expr, null);
  207. }
  208. public virtual object Evaluate (XPathExpression expr, XPathNodeIterator context)
  209. {
  210. return Evaluate (expr, context, null);
  211. }
  212. internal virtual object Evaluate (XPathExpression expr, XPathNodeIterator context, NSResolver ctx)
  213. {
  214. CompiledExpression cexpr = (CompiledExpression) expr;
  215. if (ctx == null)
  216. ctx = cexpr.NamespaceManager;
  217. if (context == null)
  218. context = new NullIterator (this, ctx);
  219. BaseIterator iterContext = (BaseIterator) context;
  220. iterContext.NamespaceManager = ctx;
  221. return cexpr.Evaluate (iterContext);
  222. }
  223. internal XPathNodeIterator EvaluateNodeSet (XPathExpression expr, XPathNodeIterator context, NSResolver ctx)
  224. {
  225. CompiledExpression cexpr = (CompiledExpression) expr;
  226. if (ctx == null)
  227. ctx = cexpr.NamespaceManager;
  228. if (context == null)
  229. context = new NullIterator (this, cexpr.NamespaceManager);
  230. BaseIterator iterContext = (BaseIterator) context;
  231. iterContext.NamespaceManager = ctx;
  232. return cexpr.EvaluateNodeSet (iterContext);
  233. }
  234. internal string EvaluateString (XPathExpression expr, XPathNodeIterator context, NSResolver ctx)
  235. {
  236. CompiledExpression cexpr = (CompiledExpression) expr;
  237. if (ctx == null)
  238. ctx = cexpr.NamespaceManager;
  239. if (context == null)
  240. context = new NullIterator (this, cexpr.NamespaceManager);
  241. BaseIterator iterContext = (BaseIterator) context;
  242. iterContext.NamespaceManager = ctx;
  243. return cexpr.EvaluateString (iterContext);
  244. }
  245. internal double EvaluateNumber (XPathExpression expr, XPathNodeIterator context, NSResolver ctx)
  246. {
  247. CompiledExpression cexpr = (CompiledExpression) expr;
  248. if (ctx == null)
  249. ctx = cexpr.NamespaceManager;
  250. if (context == null)
  251. context = new NullIterator (this, cexpr.NamespaceManager);
  252. BaseIterator iterContext = (BaseIterator) context;
  253. iterContext.NamespaceManager = ctx;
  254. return cexpr.EvaluateNumber (iterContext);
  255. }
  256. internal bool EvaluateBoolean (XPathExpression expr, XPathNodeIterator context, NSResolver ctx)
  257. {
  258. CompiledExpression cexpr = (CompiledExpression) expr;
  259. if (ctx == null)
  260. ctx = cexpr.NamespaceManager;
  261. if (context == null)
  262. context = new NullIterator (this, cexpr.NamespaceManager);
  263. BaseIterator iterContext = (BaseIterator) context;
  264. iterContext.NamespaceManager = ctx;
  265. return cexpr.EvaluateBoolean (iterContext);
  266. }
  267. #if NET_2_0
  268. public virtual string GetAttribute (string localName, string namespaceURI)
  269. {
  270. XPathNavigator nav = Clone ();
  271. if (nav.MoveToAttribute (localName, namespaceURI))
  272. return nav.Value;
  273. else
  274. return String.Empty;
  275. }
  276. public virtual string GetNamespace (string name)
  277. {
  278. XPathNavigator nav = Clone ();
  279. if (nav.MoveToNamespace (name))
  280. return nav.Value;
  281. else
  282. return String.Empty;
  283. }
  284. #else
  285. public abstract string GetAttribute (string localName, string namespaceURI);
  286. public abstract string GetNamespace (string name);
  287. #endif
  288. object ICloneable.Clone ()
  289. {
  290. return Clone ();
  291. }
  292. public virtual bool IsDescendant (XPathNavigator nav)
  293. {
  294. if (nav != null)
  295. {
  296. nav = nav.Clone ();
  297. while (nav.MoveToParent ())
  298. {
  299. if (IsSamePosition (nav))
  300. return true;
  301. }
  302. }
  303. return false;
  304. }
  305. public abstract bool IsSamePosition (XPathNavigator other);
  306. public virtual bool Matches (string xpath)
  307. {
  308. return Matches (Compile (xpath));
  309. }
  310. public virtual bool Matches (XPathExpression expr)
  311. {
  312. Expression e = ((CompiledExpression) expr).ExpressionNode;
  313. if (e is ExprRoot)
  314. return NodeType == XPathNodeType.Root;
  315. NodeTest nt = e as NodeTest;
  316. if (nt != null) {
  317. switch (nt.Axis.Axis) {
  318. case Axes.Child:
  319. case Axes.Attribute:
  320. break;
  321. default:
  322. throw new XPathException ("Only child and attribute pattern are allowed for a pattern.");
  323. }
  324. return nt.Match (((CompiledExpression)expr).NamespaceManager, this);
  325. }
  326. if (e is ExprFilter) {
  327. do {
  328. e = ((ExprFilter) e).LeftHandSide;
  329. } while (e is ExprFilter);
  330. if (e is NodeTest && !((NodeTest) e).Match (((CompiledExpression) expr).NamespaceManager, this))
  331. return false;
  332. }
  333. XPathResultType resultType = e.ReturnType;
  334. switch (resultType) {
  335. case XPathResultType.Any:
  336. case XPathResultType.NodeSet:
  337. break;
  338. default:
  339. return false;
  340. }
  341. switch (e.EvaluatedNodeType) {
  342. case XPathNodeType.Attribute:
  343. case XPathNodeType.Namespace:
  344. if (NodeType != e.EvaluatedNodeType)
  345. return false;
  346. break;
  347. }
  348. XPathNodeIterator nodes;
  349. nodes = this.Select (expr);
  350. while (nodes.MoveNext ()) {
  351. if (IsSamePosition (nodes.Current))
  352. return true;
  353. }
  354. // ancestors might select this node.
  355. XPathNavigator navigator = Clone ();
  356. while (navigator.MoveToParent ()) {
  357. nodes = navigator.Select (expr);
  358. while (nodes.MoveNext ()) {
  359. if (IsSamePosition (nodes.Current))
  360. return true;
  361. }
  362. }
  363. return false;
  364. }
  365. public abstract bool MoveTo (XPathNavigator other);
  366. #if NET_2_0
  367. public virtual bool MoveToAttribute (string localName, string namespaceURI)
  368. {
  369. if (MoveToFirstAttribute ()) {
  370. do {
  371. if (LocalName == localName && NamespaceURI == namespaceURI)
  372. return true;
  373. } while (MoveToNextAttribute ());
  374. MoveToParent ();
  375. }
  376. return false;
  377. }
  378. public virtual bool MoveToNamespace (string name)
  379. {
  380. if (MoveToFirstNamespace ()) {
  381. do {
  382. if (LocalName == name)
  383. return true;
  384. } while (MoveToNextNamespace ());
  385. MoveToParent ();
  386. }
  387. return false;
  388. }
  389. public virtual bool MoveToFirst ()
  390. {
  391. if (MoveToPrevious ()) {
  392. // It would be able to invoke MoveToPrevious() until the end, but this way would be much faster
  393. MoveToParent ();
  394. MoveToFirstChild ();
  395. return true;
  396. }
  397. return false;
  398. }
  399. public virtual void MoveToRoot ()
  400. {
  401. while (MoveToParent ())
  402. ;
  403. }
  404. #else
  405. public abstract bool MoveToAttribute (string localName, string namespaceURI);
  406. public abstract bool MoveToNamespace (string name);
  407. public abstract bool MoveToFirst ();
  408. public abstract void MoveToRoot ();
  409. #endif
  410. public abstract bool MoveToFirstAttribute ();
  411. public abstract bool MoveToFirstChild ();
  412. public bool MoveToFirstNamespace ()
  413. {
  414. return MoveToFirstNamespace (XPathNamespaceScope.All);
  415. }
  416. public abstract bool MoveToFirstNamespace (XPathNamespaceScope namespaceScope);
  417. public abstract bool MoveToId (string id);
  418. public abstract bool MoveToNext ();
  419. public abstract bool MoveToNextAttribute ();
  420. public bool MoveToNextNamespace ()
  421. {
  422. return MoveToNextNamespace (XPathNamespaceScope.All);
  423. }
  424. public abstract bool MoveToNextNamespace (XPathNamespaceScope namespaceScope);
  425. public abstract bool MoveToParent ();
  426. public abstract bool MoveToPrevious ();
  427. public virtual XPathNodeIterator Select (string xpath)
  428. {
  429. return Select (Compile (xpath));
  430. }
  431. public virtual XPathNodeIterator Select (XPathExpression expr)
  432. {
  433. return Select (expr, null);
  434. }
  435. internal virtual XPathNodeIterator Select (XPathExpression expr, NSResolver ctx)
  436. {
  437. CompiledExpression cexpr = (CompiledExpression) expr;
  438. if (ctx == null)
  439. ctx = cexpr.NamespaceManager;
  440. BaseIterator iter = new NullIterator (this, ctx);
  441. return cexpr.EvaluateNodeSet (iter);
  442. }
  443. public virtual XPathNodeIterator SelectAncestors (XPathNodeType type, bool matchSelf)
  444. {
  445. Axes axis = (matchSelf) ? Axes.AncestorOrSelf : Axes.Ancestor;
  446. return SelectTest (new NodeTypeTest (axis, type));
  447. }
  448. public virtual XPathNodeIterator SelectAncestors (string name, string namespaceURI, bool matchSelf)
  449. {
  450. if (name == null)
  451. throw new ArgumentNullException ("name");
  452. if (namespaceURI == null)
  453. throw new ArgumentNullException ("namespaceURI");
  454. Axes axis = (matchSelf) ? Axes.AncestorOrSelf : Axes.Ancestor;
  455. XmlQualifiedName qname = new XmlQualifiedName (name, namespaceURI);
  456. return SelectTest (new NodeNameTest (axis, qname, true));
  457. }
  458. public virtual XPathNodeIterator SelectChildren (XPathNodeType type)
  459. {
  460. return SelectTest (new NodeTypeTest (Axes.Child, type));
  461. }
  462. public virtual XPathNodeIterator SelectChildren (string name, string namespaceURI)
  463. {
  464. if (name == null)
  465. throw new ArgumentNullException ("name");
  466. if (namespaceURI == null)
  467. throw new ArgumentNullException ("namespaceURI");
  468. Axes axis = Axes.Child;
  469. XmlQualifiedName qname = new XmlQualifiedName (name, namespaceURI);
  470. return SelectTest (new NodeNameTest (axis, qname, true));
  471. }
  472. public virtual XPathNodeIterator SelectDescendants (XPathNodeType type, bool matchSelf)
  473. {
  474. Axes axis = (matchSelf) ? Axes.DescendantOrSelf : Axes.Descendant;
  475. return SelectTest (new NodeTypeTest (axis, type));
  476. }
  477. public virtual XPathNodeIterator SelectDescendants (string name, string namespaceURI, bool matchSelf)
  478. {
  479. if (name == null)
  480. throw new ArgumentNullException ("name");
  481. if (namespaceURI == null)
  482. throw new ArgumentNullException ("namespaceURI");
  483. Axes axis = (matchSelf) ? Axes.DescendantOrSelf : Axes.Descendant;
  484. XmlQualifiedName qname = new XmlQualifiedName (name, namespaceURI);
  485. return SelectTest (new NodeNameTest (axis, qname, true));
  486. }
  487. internal XPathNodeIterator SelectTest (NodeTest test)
  488. {
  489. return test.EvaluateNodeSet (new NullIterator (this));
  490. }
  491. public override string ToString ()
  492. {
  493. return Value;
  494. }
  495. #endregion
  496. #if NET_2_0
  497. [MonoTODO]
  498. public virtual bool CheckValidity (XmlSchemaSet schemas, ValidationEventHandler handler)
  499. {
  500. throw new NotImplementedException ();
  501. }
  502. [MonoTODO]
  503. public virtual object CopyAsObject (Type targetType)
  504. {
  505. throw new NotImplementedException ();
  506. }
  507. public virtual XPathNavigator CreateNavigator ()
  508. {
  509. return Clone ();
  510. }
  511. [MonoTODO]
  512. public virtual object Evaluate (string xpath, IXmlNamespaceResolver nsResolver)
  513. {
  514. return Evaluate (Compile (xpath), null, nsResolver);
  515. }
  516. [MonoTODO]
  517. public virtual IDictionary GetNamespacesInScope (XmlNamespaceScope scope)
  518. {
  519. throw new NotImplementedException ();
  520. }
  521. public virtual string LookupNamespace (string prefix)
  522. {
  523. return LookupNamespace (prefix, false);
  524. }
  525. public virtual string LookupNamespace (string prefix, bool atomizedNames)
  526. {
  527. XPathNavigator nav = Clone ();
  528. if (nav.NodeType != XPathNodeType.Element)
  529. nav.MoveToParent ();
  530. if (nav.MoveToNamespace (prefix)) {
  531. if (atomizedNames)
  532. return nav.NameTable.Add (nav.Value);
  533. else
  534. return nav.Value;
  535. }
  536. return null;
  537. }
  538. public virtual string LookupPrefix (string namespaceUri)
  539. {
  540. return LookupPrefix (namespaceUri, false);
  541. }
  542. [MonoTODO]
  543. public virtual string LookupPrefix (string namespaceUri, bool atomizedNames)
  544. {
  545. throw new NotImplementedException ();
  546. }
  547. public virtual bool MoveToAttribute (string localName, string namespaceURI, bool atomizedNames)
  548. {
  549. return MoveToAttribute (localName, namespaceURI);
  550. }
  551. private bool MoveTo (XPathNodeIterator iter)
  552. {
  553. if (iter.MoveNext ()) {
  554. MoveTo (iter.Current);
  555. return true;
  556. }
  557. else
  558. return false;
  559. }
  560. public virtual bool MoveToChild (XPathNodeType type)
  561. {
  562. return MoveTo (SelectChildren (type));
  563. }
  564. public virtual bool MoveToChild (string localName, string namespaceURI)
  565. {
  566. return MoveTo (SelectChildren (localName, namespaceURI));
  567. }
  568. public virtual bool MoveToChild (string localName, string namespaceURI, bool atomizedNames)
  569. {
  570. return MoveToChild (localName, namespaceURI);
  571. }
  572. public virtual bool MoveToDescendant (XPathNodeType type)
  573. {
  574. return MoveTo (SelectDescendants (type, false));
  575. }
  576. public virtual bool MoveToDescendant (string localName, string namespaceURI)
  577. {
  578. return MoveTo (SelectDescendants (localName, namespaceURI, false));
  579. }
  580. public virtual bool MoveToDescendant (string localName, string namespaceURI, bool atomizedNames)
  581. {
  582. return MoveToDescendant (localName, namespaceURI);
  583. }
  584. public virtual bool MoveToNext (string localName, string namespaceURI)
  585. {
  586. XPathNavigator nav = Clone ();
  587. while (nav.MoveToNext ()) {
  588. if (nav.LocalName == localName &&
  589. nav.NamespaceURI == namespaceURI) {
  590. MoveTo (nav);
  591. return true;
  592. }
  593. }
  594. return false;
  595. }
  596. public virtual bool MoveToNext (string localName, string namespaceURI, bool atomizedNames)
  597. {
  598. return MoveToNext (localName, namespaceURI);
  599. }
  600. public virtual bool MoveToNext (XPathNodeType type)
  601. {
  602. XPathNavigator nav = Clone ();
  603. while (nav.MoveToNext ()) {
  604. if (nav.NodeType == type) {
  605. MoveTo (nav);
  606. return true;
  607. }
  608. }
  609. return false;
  610. }
  611. [MonoTODO]
  612. public virtual XmlReader ReadSubtree ()
  613. {
  614. return new XPathNavigatorReader (this);
  615. }
  616. public virtual XPathNodeIterator Select (string xpath, IXmlNamespaceResolver nsResolver)
  617. {
  618. return Select (Compile (xpath), nsResolver);
  619. }
  620. public virtual XPathNavigator SelectSingleNode (string xpath)
  621. {
  622. return SelectSingleNode (xpath, null);
  623. }
  624. public virtual XPathNavigator SelectSingleNode (string xpath, IXmlNamespaceResolver nsResolver)
  625. {
  626. XPathExpression expr = Compile (xpath);
  627. expr.SetContext (nsResolver);
  628. return SelectSingleNode (expr);
  629. }
  630. public XPathNavigator SelectSingleNode (XPathExpression expression)
  631. {
  632. XPathNodeIterator iter = Select (expression);
  633. if (iter.MoveNext ())
  634. return iter.Current;
  635. else
  636. return null;
  637. }
  638. [MonoTODO]
  639. public override object ValueAs (Type type, IXmlNamespaceResolver nsResolver)
  640. {
  641. throw new NotImplementedException ();
  642. }
  643. [MonoTODO]
  644. public virtual void WriteSubtree (XmlWriter writer)
  645. {
  646. XmlReader st = ReadSubtree ();
  647. writer.WriteNode (st, false);
  648. }
  649. [MonoTODO]
  650. public virtual string InnerXml {
  651. get { throw new NotImplementedException (); }
  652. }
  653. [MonoTODO]
  654. public override bool IsNode {
  655. get { return true; }
  656. }
  657. [MonoTODO]
  658. public virtual IKeyComparer NavigatorComparer {
  659. get { throw new NotImplementedException (); }
  660. }
  661. [MonoTODO]
  662. public virtual string OuterXml {
  663. get {
  664. StringWriter sw = new StringWriter ();
  665. XmlTextWriter xtw = new XmlTextWriter (sw);
  666. WriteSubtree (xtw);
  667. xtw.Close ();
  668. return sw.ToString ();
  669. }
  670. }
  671. [MonoTODO]
  672. public virtual IXmlSchemaInfo SchemaInfo {
  673. get { throw new NotImplementedException (); }
  674. }
  675. [MonoTODO]
  676. public override object TypedValue {
  677. get { throw new NotImplementedException (); }
  678. }
  679. [MonoTODO]
  680. public virtual object UnderlyingObject {
  681. get { throw new NotImplementedException (); }
  682. }
  683. [MonoTODO]
  684. public override bool ValueAsBoolean {
  685. get { return XQueryConvert.StringToBoolean (Value); }
  686. }
  687. [MonoTODO]
  688. public override DateTime ValueAsDateTime {
  689. get { return XmlConvert.ToDateTime (Value); }
  690. }
  691. [MonoTODO]
  692. public override decimal ValueAsDecimal {
  693. get { return XQueryConvert.StringToDecimal (Value); }
  694. }
  695. [MonoTODO]
  696. public override double ValueAsDouble {
  697. get { return XQueryConvert.StringToDouble (Value); }
  698. }
  699. [MonoTODO]
  700. public override int ValueAsInt32 {
  701. get { return XQueryConvert.StringToInt (Value); }
  702. }
  703. [MonoTODO]
  704. public override long ValueAsInt64 {
  705. get { return XQueryConvert.StringToInteger (Value); }
  706. }
  707. [MonoTODO]
  708. public override ICollection ValueAsList {
  709. get { throw new NotImplementedException (); }
  710. }
  711. [MonoTODO]
  712. public override float ValueAsSingle {
  713. get { return XQueryConvert.StringToFloat (Value); }
  714. }
  715. [MonoTODO]
  716. public override Type ValueType {
  717. get { throw new NotImplementedException (); }
  718. }
  719. [MonoTODO]
  720. public override XmlSchemaType XmlType {
  721. get { throw new NotImplementedException (); }
  722. }
  723. [MonoTODO]
  724. protected XmlReader GetValidatingReader (XmlSchemaSet schemas, ValidationEventHandler handler, XmlSchemaType schemaType)
  725. {
  726. throw new NotImplementedException ();
  727. }
  728. #endif
  729. }
  730. }