XPathDocument2Editable.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. //
  2. // Mono.Xml.XPath.XPathDocument2Editable
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // (C)2004 Novell Inc.
  8. //
  9. // Yet another implementation of XPathEditableNavigator.
  10. // (Even runnable under MS.NET 2.0)
  11. //
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. #if NET_2_0
  33. using System;
  34. using System.Collections;
  35. using System.ComponentModel;
  36. using System.IO;
  37. using System.Xml;
  38. using System.Xml.Schema;
  39. using System.Xml.XPath;
  40. using System.Xml.Serialization;
  41. namespace Mono.Xml.XPath
  42. {
  43. /*
  44. public class Driver
  45. {
  46. public static void Main ()
  47. {
  48. try {
  49. #if true
  50. XPathDocument2 doc = new XPathDocument2 ();
  51. XPathDocument2Editable pd = new XPathDocument2Editable (doc);
  52. XPathEditableNavigator nav = pd.CreateEditor ();
  53. IChangeTracking xp = pd;
  54. #else
  55. XPathDocument doc = new XPathDocument ();
  56. XPathEditableNavigator nav = doc.CreateEditor ();
  57. IChangeTracking xp = doc;
  58. #endif
  59. doc.LoadXml ("<root/>");
  60. nav.MoveToFirstChild (); // root
  61. XmlWriter w = nav.AppendChild ();
  62. Console.WriteLine (((IChangeTracking) xp).IsChanged);
  63. w.WriteElementString ("foo", "foo_text");
  64. w.WriteElementString ("bar", "bar_text");
  65. w.WriteStartElement ("hoge");
  66. w.WriteAttributeString ("fuga", "fugafuga");
  67. w.WriteAttributeString ("unya", "unyaunya");
  68. w.WriteFullEndElement ();
  69. w.Close ();
  70. w = nav.CreateAttributes ();
  71. w.WriteStartAttribute ("namara");
  72. w.WriteString ("mokera");
  73. w.WriteEndAttribute ();
  74. w.WriteAttributeString ("beccho", "giccho");
  75. w.Close ();
  76. nav.MoveToRoot ();
  77. nav.MoveToFirstChild ();
  78. nav.MoveToFirstChild ();
  79. nav.DeleteCurrent (); // delete foo
  80. Console.WriteLine (nav.Name);
  81. nav.MoveToNext ();
  82. Console.WriteLine (nav.Name);
  83. Console.WriteLine (nav.MoveToFirstAttribute ());
  84. nav.DeleteCurrent (); // delete fuga
  85. doc.Save (Console.Out);
  86. } catch (Exception ex) {
  87. Console.WriteLine (ex);
  88. }
  89. }
  90. }
  91. */
  92. public class XPathDocument2Editable
  93. : IXPathNavigable, IXPathEditable,
  94. IRevertibleChangeTracking, IChangeTracking, IXmlSerializable
  95. {
  96. XPathDocument2 document;
  97. ArrayList changes = new ArrayList ();
  98. bool enableChangeTracking;
  99. public XPathDocument2Editable (XPathDocument2 doc)
  100. {
  101. document = doc;
  102. }
  103. #region Events
  104. public event NodeChangedEventHandler ChangeRejected;
  105. public event NodeChangedEventHandler ItemUpdated;
  106. public event NodeChangedEventHandler ItemUpdating;
  107. public event NodeChangedEventHandler ItemInserted;
  108. public event NodeChangedEventHandler ItemInserting;
  109. public event NodeChangedEventHandler ItemDeleted;
  110. public event NodeChangedEventHandler ItemDeleting;
  111. public event NodeChangedEventHandler RejectingChange;
  112. #endregion // Events
  113. public XmlNameTable NameTable {
  114. get { return document.NameTable; }
  115. }
  116. public XPathNavigator CreateNavigator ()
  117. {
  118. return document.CreateNavigator ();
  119. }
  120. public XPathEditableNavigator CreateEditor ()
  121. {
  122. return new XomEditableNavigator (this);
  123. }
  124. public XmlWriter CreateWriter ()
  125. {
  126. return CreateEditor ().AppendChild ();
  127. }
  128. public bool HasChanges ()
  129. {
  130. return IsChanged;
  131. }
  132. public bool EnableChangeTracking {
  133. get { return enableChangeTracking; }
  134. set { enableChangeTracking = value; }
  135. }
  136. #region IRevertibleChangeTracking/IChangeTracking
  137. public bool IsChanged {
  138. get { return changes.Count != 0; }
  139. }
  140. public void AcceptChanges ()
  141. {
  142. changes.Clear ();
  143. }
  144. public void RejectChanges ()
  145. {
  146. for (int i = changes.Count - 1; i >= 0; i--) {
  147. Insertion2 ins = changes [i] as Insertion2;
  148. if (ins != null) {
  149. ins.ParentNode.RemoveChild (ins.InsertedNode);
  150. continue;
  151. }
  152. Removal2 rem = changes [i] as Removal2;
  153. if (rem != null) {
  154. if (rem.RemovedNode.NodeType == XPathNodeType.Attribute) {
  155. XomElement el = (XomElement) rem.OwnerNode;
  156. el.AppendAttribute ((XomAttribute) rem.RemovedNode);
  157. }
  158. else
  159. rem.OwnerNode.InsertBefore (rem.RemovedNode, rem.NextSibling);
  160. continue;
  161. }
  162. AttributeUpdate2 au = changes [i] as AttributeUpdate2;
  163. if (au != null) {
  164. au.Element.RemoveAttribute (au.NewAttribute);
  165. if (au.OldAttribute != null)
  166. au.Element.AppendAttribute (au.OldAttribute);
  167. continue;
  168. }
  169. }
  170. changes.Clear ();
  171. }
  172. #endregion
  173. #region IXmlSerializable
  174. public void WriteXml (XmlWriter writer)
  175. {
  176. throw new NotImplementedException ();
  177. }
  178. public void ReadXml (XmlReader reader)
  179. {
  180. throw new NotImplementedException ();
  181. }
  182. public XmlSchema GetSchema ()
  183. {
  184. throw new NotImplementedException ();
  185. }
  186. #endregion
  187. internal bool DeleteNode (XomNode node)
  188. {
  189. Removal2 rem = new Removal2 ();
  190. if (node.NodeType == XPathNodeType.Attribute) {
  191. XomAttribute attr = node as XomAttribute;
  192. rem.OwnerNode = attr.Parent;
  193. rem.RemovedNode = node;
  194. ((XomElement) attr.Parent).RemoveAttribute (attr);
  195. return false;
  196. } else {
  197. rem.OwnerNode = node.Parent;
  198. rem.NextSibling = node.NextSibling;
  199. rem.RemovedNode = node;
  200. node.Parent.RemoveChild (node);
  201. return rem.NextSibling != null;
  202. }
  203. }
  204. internal XmlWriter CreateInsertionWriter (XomNode owner, XomNode previousSibling)
  205. {
  206. return new XPathDocument2InsertionWriter (owner, previousSibling, this);
  207. }
  208. internal XmlWriter CreateAttributesWriter (XomNode owner)
  209. {
  210. return new XPathDocument2AttributeWriter (owner, this);
  211. }
  212. internal void AttributeUpdate2 (XomElement element, XomAttribute oldAttr, XomAttribute newAttr)
  213. {
  214. AttributeUpdate2 au = new AttributeUpdate2 ();
  215. au.Element = element;
  216. au.OldAttribute = oldAttr;
  217. au.NewAttribute = newAttr;
  218. changes.Add (au);
  219. }
  220. internal void AppendChild (XomParentNode parent, XomNode child)
  221. {
  222. Insertion2 ins = new Insertion2 ();
  223. ins.ParentNode = parent;
  224. ins.InsertedNode = child;
  225. changes.Add (ins);
  226. }
  227. }
  228. public class XPathDocument2InsertionWriter : XmlWriter
  229. {
  230. XomNode current;
  231. XomNode previousSibling;
  232. XPathDocument2Editable document;
  233. Stack nodeStack = new Stack ();
  234. public XPathDocument2InsertionWriter (XomNode owner, XomNode previousSibling, XPathDocument2Editable doc)
  235. {
  236. this.current = (XomNode) owner;
  237. if (current == null)
  238. throw new InvalidOperationException ();
  239. this.previousSibling = previousSibling;
  240. this.document = doc;
  241. state = WriteState.Content;
  242. }
  243. WriteState state;
  244. XomAttribute attribute;
  245. public override WriteState WriteState {
  246. get { return state; }
  247. }
  248. public override void Close ()
  249. {
  250. }
  251. public override void Flush ()
  252. {
  253. }
  254. public override string LookupPrefix (string ns)
  255. {
  256. return current.LookupPrefix (ns);
  257. }
  258. public override void WriteStartAttribute (string prefix, string name, string ns)
  259. {
  260. if (state != WriteState.Content)
  261. throw new InvalidOperationException ("Current state is not inside element. Cannot start attribute.");
  262. attribute = new XomAttribute (prefix, name, ns, String.Empty);
  263. state = WriteState.Attribute;
  264. }
  265. public override void WriteProcessingInstruction (string name, string value)
  266. {
  267. XomParentNode p = current as XomParentNode;
  268. if (p == null)
  269. throw new InvalidOperationException ("Current writer node cannot have a child.");
  270. XomPI pi = new XomPI (name, value);
  271. p.AppendChild (pi);
  272. document.AppendChild (p, pi);
  273. }
  274. public override void WriteComment (string text)
  275. {
  276. XomParentNode p = current as XomParentNode;
  277. if (p == null)
  278. throw new InvalidOperationException ("Current writer node cannot have a child.");
  279. XomComment comment = new XomComment (text);
  280. p.AppendChild (comment);
  281. document.AppendChild (p, comment);
  282. }
  283. public override void WriteCData (string text)
  284. {
  285. if (attribute != null)
  286. throw new InvalidOperationException ("Current writer node is attribute. It cannot accept CDATA section.");
  287. /*
  288. XomParentNode p = current as XomParentNode;
  289. if (p == null)
  290. throw new InvalidOperationException ("Current writer node cannot have a child.");
  291. XomText cdata = new XomText (text);
  292. p.AppendChild (cdata);
  293. document.AppendChild (p, cdata);
  294. */
  295. WriteString (text);
  296. }
  297. public override void WriteStartElement (string prefix, string name, string ns)
  298. {
  299. XomParentNode p = current as XomParentNode;
  300. if (p == null)
  301. throw new InvalidOperationException ("Current writer node cannot have a child.");
  302. XomElement el = new XomElement (prefix, name, ns);
  303. p.AppendChild (el);
  304. document.AppendChild (p, el);
  305. nodeStack.Push (current);
  306. current = el;
  307. }
  308. public override void WriteEndElement ()
  309. {
  310. WriteFullEndElement ();
  311. XomElement el = current as XomElement;
  312. if (el != null && el.ChildCount == 0)
  313. el.SetIsEmpty (true);
  314. }
  315. public override void WriteFullEndElement ()
  316. {
  317. if (nodeStack.Count == 0)
  318. throw new InvalidOperationException ("No element is opened.");
  319. current = nodeStack.Pop () as XomNode;
  320. }
  321. public override void WriteDocType (string name, string pubid, string systemId, string intsubset)
  322. {
  323. throw new NotSupportedException ();
  324. }
  325. public override void WriteStartDocument ()
  326. {
  327. throw new NotSupportedException ();
  328. }
  329. public override void WriteStartDocument (bool standalone)
  330. {
  331. throw new NotSupportedException ();
  332. }
  333. public override void WriteEndDocument ()
  334. {
  335. throw new NotSupportedException ();
  336. }
  337. public override void WriteBase64 (byte [] data, int start, int length)
  338. {
  339. WriteString (Convert.ToBase64String (data, start, length));
  340. }
  341. public override void WriteRaw (char [] raw, int start, int length)
  342. {
  343. throw new NotSupportedException ();
  344. }
  345. public override void WriteRaw (string raw)
  346. {
  347. throw new NotSupportedException ();
  348. }
  349. public override void WriteSurrogateCharEntity (char msb, char lsb)
  350. {
  351. throw new NotSupportedException ();
  352. }
  353. public override void WriteCharEntity (char c)
  354. {
  355. throw new NotSupportedException ();
  356. }
  357. public override void WriteEntityRef (string entname)
  358. {
  359. throw new NotSupportedException ();
  360. }
  361. public override void WriteChars (char [] data, int start, int length)
  362. {
  363. WriteString (new string (data, start, length));
  364. }
  365. public override void WriteString (string text)
  366. {
  367. if (attribute != null)
  368. attribute.Value += text;
  369. else {
  370. XomParentNode p = current as XomParentNode;
  371. if (p == null)
  372. throw new InvalidOperationException ("Current writer node cannot have a child.");
  373. XomText xt = new XomText (text);
  374. p.AppendChild (xt);
  375. document.AppendChild (p, xt);
  376. }
  377. }
  378. public override void WriteWhitespace (string text)
  379. {
  380. if (attribute != null)
  381. attribute.Value += text;
  382. else {
  383. XomParentNode p = current as XomParentNode;
  384. if (p == null)
  385. throw new InvalidOperationException ("Current writer node cannot have a child.");
  386. XomWhitespace ws = new XomWhitespace (text);
  387. p.AppendChild (ws);
  388. document.AppendChild (p, ws);
  389. }
  390. }
  391. public override void WriteEndAttribute ()
  392. {
  393. XomElement element = current as XomElement;
  394. if (state != WriteState.Attribute || element == null)
  395. throw new InvalidOperationException ("Current state is not inside attribute. Cannot close attribute.");
  396. XomAttribute old = element.GetAttribute (attribute.LocalName, attribute.Namespace);
  397. element.AppendAttribute (attribute);
  398. document.AttributeUpdate2 (element, old, attribute);
  399. attribute = null;
  400. state = WriteState.Content;
  401. }
  402. }
  403. public class XPathDocument2AttributeWriter : XmlWriter
  404. {
  405. XomElement element;
  406. XPathDocument2Editable document;
  407. public XPathDocument2AttributeWriter (XomNode owner, XPathDocument2Editable doc)
  408. {
  409. element = owner as XomElement;
  410. if (element == null)
  411. throw new ArgumentException ("To write attributes, current node must be an element.");
  412. state = WriteState.Content;
  413. document = doc;
  414. }
  415. WriteState state;
  416. XomAttribute attribute;
  417. public override WriteState WriteState {
  418. get { return state; }
  419. }
  420. public override void Close ()
  421. {
  422. }
  423. public override void Flush ()
  424. {
  425. }
  426. public override string LookupPrefix (string ns)
  427. {
  428. return element.LookupPrefix (ns);
  429. }
  430. public override void WriteStartAttribute (string prefix, string name, string ns)
  431. {
  432. if (state != WriteState.Content)
  433. throw new InvalidOperationException ("Current state is not inside element. Cannot start attribute.");
  434. attribute = new XomAttribute (prefix, name, ns, String.Empty);
  435. state = WriteState.Attribute;
  436. }
  437. public override void WriteProcessingInstruction (string name, string value)
  438. {
  439. throw new NotSupportedException ();
  440. }
  441. public override void WriteComment (string text)
  442. {
  443. throw new NotSupportedException ();
  444. }
  445. public override void WriteCData (string text)
  446. {
  447. throw new NotSupportedException ();
  448. }
  449. public override void WriteStartElement (string prefix, string name, string ns)
  450. {
  451. throw new NotSupportedException ();
  452. }
  453. public override void WriteEndElement ()
  454. {
  455. throw new NotSupportedException ();
  456. }
  457. public override void WriteFullEndElement ()
  458. {
  459. throw new NotSupportedException ();
  460. }
  461. public override void WriteDocType (string name, string pubid, string systemId, string intsubset)
  462. {
  463. throw new NotSupportedException ();
  464. }
  465. public override void WriteStartDocument ()
  466. {
  467. throw new NotSupportedException ();
  468. }
  469. public override void WriteStartDocument (bool standalone)
  470. {
  471. throw new NotSupportedException ();
  472. }
  473. public override void WriteEndDocument ()
  474. {
  475. throw new NotSupportedException ();
  476. }
  477. public override void WriteBase64 (byte [] data, int start, int length)
  478. {
  479. throw new NotSupportedException ();
  480. }
  481. public override void WriteRaw (char [] raw, int start, int length)
  482. {
  483. throw new NotSupportedException ();
  484. }
  485. public override void WriteRaw (string raw)
  486. {
  487. throw new NotSupportedException ();
  488. }
  489. public override void WriteSurrogateCharEntity (char msb, char lsb)
  490. {
  491. throw new NotSupportedException ();
  492. }
  493. public override void WriteCharEntity (char c)
  494. {
  495. throw new NotSupportedException ();
  496. }
  497. public override void WriteEntityRef (string entname)
  498. {
  499. throw new NotSupportedException ();
  500. }
  501. public override void WriteChars (char [] data, int start, int length)
  502. {
  503. WriteString (new string (data, start, length));
  504. }
  505. public override void WriteString (string text)
  506. {
  507. if (state != WriteState.Attribute)
  508. throw new InvalidOperationException ("Current state is not inside attribute. Cannot write attribute value.");
  509. attribute.Value += text;
  510. }
  511. public override void WriteWhitespace (string text)
  512. {
  513. if (state != WriteState.Attribute)
  514. throw new InvalidOperationException ("Current state is not inside attribute. Cannot write attribute value.");
  515. else
  516. attribute.Value += text;
  517. }
  518. public override void WriteEndAttribute ()
  519. {
  520. if (state != WriteState.Attribute)
  521. throw new InvalidOperationException ("Current state is not inside attribute. Cannot close attribute.");
  522. XomAttribute old = element.GetAttribute (attribute.LocalName, attribute.Namespace);
  523. element.AppendAttribute (attribute);
  524. document.AttributeUpdate2 (element, old, attribute);
  525. attribute = null;
  526. state = WriteState.Content;
  527. }
  528. }
  529. public class Insertion2
  530. {
  531. // AppendChild : last child / true
  532. // InsertBefore : current node / false
  533. // InsertAfter : current node / true
  534. // PrependChild : first child / false
  535. public XomParentNode ParentNode;
  536. public XomNode InsertedNode;
  537. public bool Afterward;
  538. }
  539. public class Removal2
  540. {
  541. public XomParentNode OwnerNode;
  542. public XomNode NextSibling;
  543. public XomNode RemovedNode;
  544. }
  545. public class AttributeUpdate2
  546. {
  547. public XomElement Element;
  548. public XomAttribute NewAttribute;
  549. public XomAttribute OldAttribute;
  550. }
  551. public class XomEditableNavigator : XPathEditableNavigator, IHasXomNode
  552. {
  553. XPathDocument2Editable document;
  554. XPathNavigator navigator;
  555. public XomEditableNavigator (XPathDocument2Editable doc)
  556. {
  557. document = doc;
  558. navigator = doc.CreateNavigator ();
  559. }
  560. public XomEditableNavigator (XomEditableNavigator nav)
  561. {
  562. document = nav.document;
  563. navigator = nav.navigator.Clone ();
  564. }
  565. public override string BaseURI {
  566. get { return navigator.BaseURI; }
  567. }
  568. public override bool IsEmptyElement {
  569. get { return navigator.IsEmptyElement; }
  570. }
  571. public override string LocalName {
  572. get { return navigator.LocalName; }
  573. }
  574. public override XmlNameTable NameTable {
  575. get { return navigator.NameTable; }
  576. }
  577. public override string Name {
  578. get { return navigator.Name; }
  579. }
  580. public override string NamespaceURI {
  581. get { return navigator.NamespaceURI; }
  582. }
  583. public override XPathNodeType NodeType {
  584. get { return navigator.NodeType; }
  585. }
  586. public override string Prefix {
  587. get { return navigator.Prefix; }
  588. }
  589. public override string Value {
  590. get { return navigator.Value; }
  591. }
  592. public override XPathNavigator Clone ()
  593. {
  594. return new XomEditableNavigator (this);
  595. }
  596. public override XPathNavigator CreateNavigator ()
  597. {
  598. return navigator.Clone ();
  599. }
  600. public XomNode GetNode ()
  601. {
  602. return ((IHasXomNode) navigator).GetNode ();
  603. }
  604. public override bool IsSamePosition (XPathNavigator other)
  605. {
  606. XomEditableNavigator nav = other as XomEditableNavigator;
  607. if (nav != null)
  608. return navigator.IsSamePosition (nav.navigator);
  609. else
  610. return navigator.IsSamePosition (nav);
  611. }
  612. public override bool MoveTo (XPathNavigator other)
  613. {
  614. XomEditableNavigator nav = other as XomEditableNavigator;
  615. if (nav != null)
  616. return navigator.MoveTo (nav.navigator);
  617. else
  618. return navigator.MoveTo (nav);
  619. }
  620. public override bool MoveToFirstAttribute ()
  621. {
  622. return navigator.MoveToFirstAttribute ();
  623. }
  624. public override bool MoveToFirstChild ()
  625. {
  626. return navigator.MoveToFirstChild ();
  627. }
  628. public override bool MoveToFirstNamespace (XPathNamespaceScope scope)
  629. {
  630. return navigator.MoveToFirstNamespace (scope);
  631. }
  632. public override bool MoveToId (string id)
  633. {
  634. return navigator.MoveToId (id);
  635. }
  636. public override bool MoveToNext ()
  637. {
  638. return navigator.MoveToNext ();
  639. }
  640. public override bool MoveToNextAttribute ()
  641. {
  642. return navigator.MoveToNextAttribute ();
  643. }
  644. public override bool MoveToNextNamespace (XPathNamespaceScope scope)
  645. {
  646. return navigator.MoveToNextNamespace (scope);
  647. }
  648. public override bool MoveToParent ()
  649. {
  650. return navigator.MoveToParent ();
  651. }
  652. public override bool MoveToPrevious ()
  653. {
  654. return navigator.MoveToPrevious ();
  655. }
  656. public override void Validate (XmlSchemaSet schemas, ValidationEventHandler handler)
  657. {
  658. throw new NotImplementedException ();
  659. /*
  660. // FIXME: use handler
  661. XmlReaderSettings settings = new XmlReaderSettings ();
  662. settings.Schemas.Add (schemas);
  663. settings.NameTable = this.NameTable;
  664. settings.XsdValidate = true;
  665. settings.DtdValidate = false;
  666. XmlReader xvr = XmlReader.Create (new XPathNavigatorReader (this), settings);
  667. while (!xvr.EOF)
  668. xvr.Read ();
  669. */
  670. }
  671. public override XmlWriter AppendChild ()
  672. {
  673. XomNode n = ((IHasXomNode) navigator).GetNode ();
  674. if (n == null)
  675. throw new InvalidOperationException ("Should not happen.");
  676. return document.CreateInsertionWriter (n, null);
  677. }
  678. public override XmlWriter InsertBefore ()
  679. {
  680. XomNode n = ((IHasXomNode) navigator).GetNode ();
  681. return document.CreateInsertionWriter (n.Parent, n.PreviousSibling);
  682. }
  683. public override XmlWriter CreateAttributes ()
  684. {
  685. XomNode n = ((IHasXomNode) navigator).GetNode ();
  686. return document.CreateInsertionWriter (n, null);
  687. }
  688. public override bool DeleteCurrent ()
  689. {
  690. XomNode n = ((IHasXomNode) navigator).GetNode ();
  691. if (!navigator.MoveToNext ())
  692. navigator.MoveToParent ();
  693. return document.DeleteNode (n);
  694. }
  695. public override void SetValue (object value)
  696. {
  697. XomNode n = ((IHasXomNode) navigator).GetNode ();
  698. int count = n.ChildCount;
  699. while (n.FirstChild != null)
  700. document.DeleteNode (n.FirstChild);
  701. XmlWriter w = document.CreateInsertionWriter (n, null);
  702. // FIXME: Hmm, it does not look like using it.
  703. w.WriteFromObject (value);
  704. w.Close ();
  705. }
  706. }
  707. }
  708. #endif