XPathDocument2Editable.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  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.UpdateAttribute ((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. if (au.OldAttribute != null)
  165. au.Element.UpdateAttribute (au.OldAttribute);
  166. else
  167. au.Element.RemoveAttribute (au.NewAttribute);
  168. continue;
  169. }
  170. }
  171. changes.Clear ();
  172. }
  173. #endregion
  174. #region IXmlSerializable
  175. public void WriteXml (XmlWriter writer)
  176. {
  177. throw new NotImplementedException ();
  178. }
  179. public void ReadXml (XmlReader reader)
  180. {
  181. throw new NotImplementedException ();
  182. }
  183. public XmlSchema GetSchema ()
  184. {
  185. throw new NotImplementedException ();
  186. }
  187. #endregion
  188. internal bool DeleteNode (XomNode node)
  189. {
  190. Removal2 rem = new Removal2 ();
  191. if (node.NodeType == XPathNodeType.Attribute) {
  192. XomAttribute attr = node as XomAttribute;
  193. rem.OwnerNode = attr.Parent;
  194. rem.RemovedNode = node;
  195. ((XomElement) attr.Parent).RemoveAttribute (attr);
  196. return false;
  197. } else {
  198. rem.OwnerNode = node.Parent;
  199. rem.NextSibling = node.NextSibling;
  200. rem.RemovedNode = node;
  201. node.Parent.RemoveChild (node);
  202. return rem.NextSibling != null;
  203. }
  204. }
  205. internal XmlWriter CreateInsertionWriter (XomNode owner, XomNode previousSibling)
  206. {
  207. return new XPathDocument2InsertionWriter (owner, previousSibling, this);
  208. }
  209. internal XmlWriter CreateAttributesWriter (XomNode owner)
  210. {
  211. return new XPathDocument2AttributeWriter (owner, this);
  212. }
  213. internal void AttributeUpdate2 (XomElement element, XomAttribute oldAttr, XomAttribute newAttr)
  214. {
  215. AttributeUpdate2 au = new AttributeUpdate2 ();
  216. au.Element = element;
  217. au.OldAttribute = oldAttr;
  218. au.NewAttribute = newAttr;
  219. changes.Add (au);
  220. }
  221. internal void AppendChild (XomParentNode parent, XomNode child)
  222. {
  223. Insertion2 ins = new Insertion2 ();
  224. ins.ParentNode = parent;
  225. ins.InsertedNode = child;
  226. changes.Add (ins);
  227. }
  228. }
  229. public class XPathDocument2InsertionWriter : XmlWriter
  230. {
  231. XomNode current;
  232. XomNode previousSibling;
  233. XPathDocument2Editable document;
  234. Stack nodeStack = new Stack ();
  235. public XPathDocument2InsertionWriter (XomNode owner, XomNode previousSibling, XPathDocument2Editable doc)
  236. {
  237. this.current = (XomNode) owner;
  238. if (current == null)
  239. throw new InvalidOperationException ();
  240. this.previousSibling = previousSibling;
  241. this.document = doc;
  242. state = WriteState.Content;
  243. }
  244. WriteState state;
  245. XomAttribute attribute;
  246. public override WriteState WriteState {
  247. get { return state; }
  248. }
  249. public override void Close ()
  250. {
  251. }
  252. public override void Flush ()
  253. {
  254. }
  255. public override string LookupPrefix (string ns)
  256. {
  257. return current.LookupPrefix (ns);
  258. }
  259. public override void WriteStartAttribute (string prefix, string name, string ns)
  260. {
  261. if (state != WriteState.Content)
  262. throw new InvalidOperationException ("Current state is not inside element. Cannot start attribute.");
  263. attribute = new XomAttribute (prefix, name, ns, String.Empty);
  264. state = WriteState.Attribute;
  265. }
  266. public override void WriteProcessingInstruction (string name, string value)
  267. {
  268. XomParentNode p = current as XomParentNode;
  269. if (p == null)
  270. throw new InvalidOperationException ("Current writer node cannot have a child.");
  271. XomPI pi = new XomPI (name, value);
  272. p.AppendChild (pi);
  273. document.AppendChild (p, pi);
  274. }
  275. public override void WriteComment (string text)
  276. {
  277. XomParentNode p = current as XomParentNode;
  278. if (p == null)
  279. throw new InvalidOperationException ("Current writer node cannot have a child.");
  280. XomComment comment = new XomComment (text);
  281. p.AppendChild (comment);
  282. document.AppendChild (p, comment);
  283. }
  284. public override void WriteCData (string text)
  285. {
  286. if (attribute != null)
  287. throw new InvalidOperationException ("Current writer node is attribute. It cannot accept CDATA section.");
  288. /*
  289. XomParentNode p = current as XomParentNode;
  290. if (p == null)
  291. throw new InvalidOperationException ("Current writer node cannot have a child.");
  292. XomText cdata = new XomText (text);
  293. p.AppendChild (cdata);
  294. document.AppendChild (p, cdata);
  295. */
  296. WriteString (text);
  297. }
  298. public override void WriteStartElement (string prefix, string name, string ns)
  299. {
  300. XomParentNode p = current as XomParentNode;
  301. if (p == null)
  302. throw new InvalidOperationException ("Current writer node cannot have a child.");
  303. XomElement el = new XomElement (prefix, name, ns);
  304. p.AppendChild (el);
  305. document.AppendChild (p, el);
  306. nodeStack.Push (current);
  307. current = el;
  308. }
  309. public override void WriteEndElement ()
  310. {
  311. WriteFullEndElement ();
  312. XomElement el = current as XomElement;
  313. if (el != null && el.ChildCount == 0)
  314. el.SetIsEmpty (true);
  315. }
  316. public override void WriteFullEndElement ()
  317. {
  318. if (nodeStack.Count == 0)
  319. throw new InvalidOperationException ("No element is opened.");
  320. current = nodeStack.Pop () as XomNode;
  321. }
  322. public override void WriteDocType (string name, string pubid, string systemId, string intsubset)
  323. {
  324. throw new NotSupportedException ();
  325. }
  326. public override void WriteStartDocument ()
  327. {
  328. throw new NotSupportedException ();
  329. }
  330. public override void WriteStartDocument (bool standalone)
  331. {
  332. throw new NotSupportedException ();
  333. }
  334. public override void WriteEndDocument ()
  335. {
  336. throw new NotSupportedException ();
  337. }
  338. public override void WriteBase64 (byte [] data, int start, int length)
  339. {
  340. WriteString (Convert.ToBase64String (data, start, length));
  341. }
  342. public override void WriteRaw (char [] raw, int start, int length)
  343. {
  344. throw new NotSupportedException ();
  345. }
  346. public override void WriteRaw (string raw)
  347. {
  348. throw new NotSupportedException ();
  349. }
  350. public override void WriteSurrogateCharEntity (char msb, char lsb)
  351. {
  352. throw new NotSupportedException ();
  353. }
  354. public override void WriteCharEntity (char c)
  355. {
  356. throw new NotSupportedException ();
  357. }
  358. public override void WriteEntityRef (string entname)
  359. {
  360. throw new NotSupportedException ();
  361. }
  362. public override void WriteChars (char [] data, int start, int length)
  363. {
  364. WriteString (new string (data, start, length));
  365. }
  366. public override void WriteString (string text)
  367. {
  368. if (attribute != null)
  369. attribute.Value += text;
  370. else {
  371. XomParentNode p = current as XomParentNode;
  372. if (p == null)
  373. throw new InvalidOperationException ("Current writer node cannot have a child.");
  374. XomText xt = new XomText (text);
  375. p.AppendChild (xt);
  376. document.AppendChild (p, xt);
  377. }
  378. }
  379. public override void WriteWhitespace (string text)
  380. {
  381. if (attribute != null)
  382. attribute.Value += text;
  383. else {
  384. XomParentNode p = current as XomParentNode;
  385. if (p == null)
  386. throw new InvalidOperationException ("Current writer node cannot have a child.");
  387. XomWhitespace ws = new XomWhitespace (text);
  388. p.AppendChild (ws);
  389. document.AppendChild (p, ws);
  390. }
  391. }
  392. public override void WriteEndAttribute ()
  393. {
  394. XomElement element = current as XomElement;
  395. if (state != WriteState.Attribute || element == null)
  396. throw new InvalidOperationException ("Current state is not inside attribute. Cannot close attribute.");
  397. XomAttribute old = element.GetAttribute (attribute.LocalName, attribute.Namespace);
  398. element.UpdateAttribute (attribute);
  399. document.AttributeUpdate2 (element, old, attribute);
  400. attribute = null;
  401. state = WriteState.Content;
  402. }
  403. }
  404. public class XPathDocument2AttributeWriter : XmlWriter
  405. {
  406. XomElement element;
  407. XPathDocument2Editable document;
  408. public XPathDocument2AttributeWriter (XomNode owner, XPathDocument2Editable doc)
  409. {
  410. element = owner as XomElement;
  411. if (element == null)
  412. throw new ArgumentException ("To write attributes, current node must be an element.");
  413. state = WriteState.Content;
  414. document = doc;
  415. }
  416. WriteState state;
  417. XomAttribute attribute;
  418. public override WriteState WriteState {
  419. get { return state; }
  420. }
  421. public override void Close ()
  422. {
  423. }
  424. public override void Flush ()
  425. {
  426. }
  427. public override string LookupPrefix (string ns)
  428. {
  429. return element.LookupPrefix (ns);
  430. }
  431. public override void WriteStartAttribute (string prefix, string name, string ns)
  432. {
  433. if (state != WriteState.Content)
  434. throw new InvalidOperationException ("Current state is not inside element. Cannot start attribute.");
  435. attribute = new XomAttribute (prefix, name, ns, String.Empty);
  436. state = WriteState.Attribute;
  437. }
  438. public override void WriteProcessingInstruction (string name, string value)
  439. {
  440. throw new NotSupportedException ();
  441. }
  442. public override void WriteComment (string text)
  443. {
  444. throw new NotSupportedException ();
  445. }
  446. public override void WriteCData (string text)
  447. {
  448. throw new NotSupportedException ();
  449. }
  450. public override void WriteStartElement (string prefix, string name, string ns)
  451. {
  452. throw new NotSupportedException ();
  453. }
  454. public override void WriteEndElement ()
  455. {
  456. throw new NotSupportedException ();
  457. }
  458. public override void WriteFullEndElement ()
  459. {
  460. throw new NotSupportedException ();
  461. }
  462. public override void WriteDocType (string name, string pubid, string systemId, string intsubset)
  463. {
  464. throw new NotSupportedException ();
  465. }
  466. public override void WriteStartDocument ()
  467. {
  468. throw new NotSupportedException ();
  469. }
  470. public override void WriteStartDocument (bool standalone)
  471. {
  472. throw new NotSupportedException ();
  473. }
  474. public override void WriteEndDocument ()
  475. {
  476. throw new NotSupportedException ();
  477. }
  478. public override void WriteBase64 (byte [] data, int start, int length)
  479. {
  480. throw new NotSupportedException ();
  481. }
  482. public override void WriteRaw (char [] raw, int start, int length)
  483. {
  484. throw new NotSupportedException ();
  485. }
  486. public override void WriteRaw (string raw)
  487. {
  488. throw new NotSupportedException ();
  489. }
  490. public override void WriteSurrogateCharEntity (char msb, char lsb)
  491. {
  492. throw new NotSupportedException ();
  493. }
  494. public override void WriteCharEntity (char c)
  495. {
  496. throw new NotSupportedException ();
  497. }
  498. public override void WriteEntityRef (string entname)
  499. {
  500. throw new NotSupportedException ();
  501. }
  502. public override void WriteChars (char [] data, int start, int length)
  503. {
  504. WriteString (new string (data, start, length));
  505. }
  506. public override void WriteString (string text)
  507. {
  508. if (state != WriteState.Attribute)
  509. throw new InvalidOperationException ("Current state is not inside attribute. Cannot write attribute value.");
  510. attribute.Value += text;
  511. }
  512. public override void WriteWhitespace (string text)
  513. {
  514. if (state != WriteState.Attribute)
  515. throw new InvalidOperationException ("Current state is not inside attribute. Cannot write attribute value.");
  516. else
  517. attribute.Value += text;
  518. }
  519. public override void WriteEndAttribute ()
  520. {
  521. if (state != WriteState.Attribute)
  522. throw new InvalidOperationException ("Current state is not inside attribute. Cannot close attribute.");
  523. XomAttribute old = element.GetAttribute (attribute.LocalName, attribute.Namespace);
  524. element.UpdateAttribute (attribute);
  525. document.AttributeUpdate2 (element, old, attribute);
  526. attribute = null;
  527. state = WriteState.Content;
  528. }
  529. }
  530. public class Insertion2
  531. {
  532. // AppendChild : last child / true
  533. // InsertBefore : current node / false
  534. // InsertAfter : current node / true
  535. // PrependChild : first child / false
  536. public XomParentNode ParentNode;
  537. public XomNode InsertedNode;
  538. public bool Afterward;
  539. }
  540. public class Removal2
  541. {
  542. public XomParentNode OwnerNode;
  543. public XomNode NextSibling;
  544. public XomNode RemovedNode;
  545. }
  546. public class AttributeUpdate2
  547. {
  548. public XomElement Element;
  549. public XomAttribute NewAttribute;
  550. public XomAttribute OldAttribute;
  551. }
  552. public class XomEditableNavigator : XPathEditableNavigator, IHasXomNode
  553. {
  554. XPathDocument2Editable document;
  555. XPathNavigator navigator;
  556. public XomEditableNavigator (XPathDocument2Editable doc)
  557. {
  558. document = doc;
  559. navigator = doc.CreateNavigator ();
  560. }
  561. public XomEditableNavigator (XomEditableNavigator nav)
  562. {
  563. document = nav.document;
  564. navigator = nav.navigator.Clone ();
  565. }
  566. public override string BaseURI {
  567. get { return navigator.BaseURI; }
  568. }
  569. public override bool IsEmptyElement {
  570. get { return navigator.IsEmptyElement; }
  571. }
  572. public override string LocalName {
  573. get { return navigator.LocalName; }
  574. }
  575. public override XmlNameTable NameTable {
  576. get { return navigator.NameTable; }
  577. }
  578. public override string Name {
  579. get { return navigator.Name; }
  580. }
  581. public override string NamespaceURI {
  582. get { return navigator.NamespaceURI; }
  583. }
  584. public override XPathNodeType NodeType {
  585. get { return navigator.NodeType; }
  586. }
  587. public override string Prefix {
  588. get { return navigator.Prefix; }
  589. }
  590. public override string Value {
  591. get { return navigator.Value; }
  592. }
  593. public override XPathNavigator Clone ()
  594. {
  595. return new XomEditableNavigator (this);
  596. }
  597. public override XPathNavigator CreateNavigator ()
  598. {
  599. return navigator.Clone ();
  600. }
  601. public XomNode GetNode ()
  602. {
  603. return ((IHasXomNode) navigator).GetNode ();
  604. }
  605. public override bool IsSamePosition (XPathNavigator other)
  606. {
  607. XomEditableNavigator nav = other as XomEditableNavigator;
  608. if (nav != null)
  609. return navigator.IsSamePosition (nav.navigator);
  610. else
  611. return navigator.IsSamePosition (nav);
  612. }
  613. public override bool MoveTo (XPathNavigator other)
  614. {
  615. XomEditableNavigator nav = other as XomEditableNavigator;
  616. if (nav != null)
  617. return navigator.MoveTo (nav.navigator);
  618. else
  619. return navigator.MoveTo (nav);
  620. }
  621. public override bool MoveToFirstAttribute ()
  622. {
  623. return navigator.MoveToFirstAttribute ();
  624. }
  625. public override bool MoveToFirstChild ()
  626. {
  627. return navigator.MoveToFirstChild ();
  628. }
  629. public override bool MoveToFirstNamespace (XPathNamespaceScope scope)
  630. {
  631. return navigator.MoveToFirstNamespace (scope);
  632. }
  633. public override bool MoveToId (string id)
  634. {
  635. return navigator.MoveToId (id);
  636. }
  637. public override bool MoveToNext ()
  638. {
  639. return navigator.MoveToNext ();
  640. }
  641. public override bool MoveToNextAttribute ()
  642. {
  643. return navigator.MoveToNextAttribute ();
  644. }
  645. public override bool MoveToNextNamespace (XPathNamespaceScope scope)
  646. {
  647. return navigator.MoveToNextNamespace (scope);
  648. }
  649. public override bool MoveToParent ()
  650. {
  651. return navigator.MoveToParent ();
  652. }
  653. public override bool MoveToPrevious ()
  654. {
  655. return navigator.MoveToPrevious ();
  656. }
  657. public override void Validate (XmlSchemaSet schemas, ValidationEventHandler handler)
  658. {
  659. throw new NotImplementedException ();
  660. /*
  661. // FIXME: use handler
  662. XmlReaderSettings settings = new XmlReaderSettings ();
  663. settings.Schemas.Add (schemas);
  664. settings.NameTable = this.NameTable;
  665. settings.XsdValidate = true;
  666. settings.DtdValidate = false;
  667. XmlReader xvr = XmlReader.Create (new XPathNavigatorReader (this), settings);
  668. while (!xvr.EOF)
  669. xvr.Read ();
  670. */
  671. }
  672. public override XmlWriter AppendChild ()
  673. {
  674. XomNode n = ((IHasXomNode) navigator).GetNode ();
  675. if (n == null)
  676. throw new InvalidOperationException ("Should not happen.");
  677. return document.CreateInsertionWriter (n, null);
  678. }
  679. public override XmlWriter InsertBefore ()
  680. {
  681. XomNode n = ((IHasXomNode) navigator).GetNode ();
  682. return document.CreateInsertionWriter (n.Parent, n.PreviousSibling);
  683. }
  684. public override XmlWriter CreateAttributes ()
  685. {
  686. XomNode n = ((IHasXomNode) navigator).GetNode ();
  687. return document.CreateInsertionWriter (n, null);
  688. }
  689. public override bool DeleteCurrent ()
  690. {
  691. XomNode n = ((IHasXomNode) navigator).GetNode ();
  692. if (!navigator.MoveToNext ())
  693. navigator.MoveToParent ();
  694. return document.DeleteNode (n);
  695. }
  696. public override void SetValue (object value)
  697. {
  698. XomNode n = ((IHasXomNode) navigator).GetNode ();
  699. int count = n.ChildCount;
  700. for (int i = 0; i < count; i++)
  701. document.DeleteNode (n.GetChild (i));
  702. XmlWriter w = document.CreateInsertionWriter (n, null);
  703. // FIXME: Hmm, it does not look like using it.
  704. w.WriteFromObject (value);
  705. w.Close ();
  706. }
  707. }
  708. }
  709. #endif