XPathNavigator.cs 21 KB

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