XPathDocument.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. //
  2. // System.Xml.XPath.XPathDocument
  3. //
  4. // Authors:
  5. // Tim Coleman ([email protected])
  6. // Atsushi Enomoto ([email protected])
  7. //
  8. // (C) Copyright 2002 Tim Coleman
  9. // (C) 2003 Atsushi Enomoto
  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 System.Text;
  37. using Mono.Xml.XPath;
  38. namespace System.Xml.XPath
  39. {
  40. public class XPathDocument : IXPathNavigable
  41. {
  42. DTMXPathDocument document;
  43. #region Constructors
  44. public XPathDocument (Stream stream)
  45. {
  46. XmlValidatingReader vr = new XmlValidatingReader (new XmlTextReader (stream));
  47. vr.ValidationType = ValidationType.None;
  48. Initialize (vr, XmlSpace.None);
  49. }
  50. public XPathDocument (string uri)
  51. : this (uri, XmlSpace.None)
  52. {
  53. }
  54. public XPathDocument (TextReader reader)
  55. {
  56. XmlValidatingReader vr = new XmlValidatingReader (new XmlTextReader (reader));
  57. vr.ValidationType = ValidationType.None;
  58. Initialize (vr, XmlSpace.None);
  59. }
  60. public XPathDocument (XmlReader reader)
  61. : this (reader, XmlSpace.None)
  62. {
  63. }
  64. public XPathDocument (string uri, XmlSpace space)
  65. {
  66. XmlValidatingReader vr = null;
  67. try {
  68. vr = new XmlValidatingReader (new XmlTextReader (uri));
  69. vr.ValidationType = ValidationType.None;
  70. Initialize (vr, space);
  71. } finally {
  72. if (vr != null)
  73. vr.Close ();
  74. }
  75. }
  76. public XPathDocument (XmlReader reader, XmlSpace space)
  77. {
  78. Initialize (reader, space);
  79. }
  80. private void Initialize (XmlReader reader, XmlSpace space)
  81. {
  82. document = new DTMXPathDocumentBuilder (reader, space).CreateDocument ();
  83. }
  84. #endregion
  85. #region Events
  86. #if NET_2_0
  87. public event NodeChangedEventHandler ChangeRejected;
  88. public event NodeChangedEventHandler ItemChanged;
  89. public event NodeChangedEventHandler ItemChanging;
  90. public event NodeChangedEventHandler ItemInserted;
  91. public event NodeChangedEventHandler ItemInserting;
  92. public event NodeChangedEventHandler ItemRemoved;
  93. public event NodeChangedEventHandler ItemRemoving;
  94. public event NodeChangedEventHandler RejectingChange;
  95. #endif // NET_2_0
  96. #endregion // Events
  97. #region Properties
  98. #if NET_2_0
  99. [MonoTODO]
  100. public virtual bool ContainsListCollection {
  101. get { throw new NotImplementedException (); }
  102. }
  103. [MonoTODO]
  104. public bool EnableChangeTracking {
  105. get { throw new NotImplementedException (); }
  106. set { throw new NotImplementedException (); }
  107. }
  108. [MonoTODO]
  109. public Encoding Encoding {
  110. get { throw new NotImplementedException (); }
  111. set { throw new NotImplementedException (); }
  112. }
  113. [MonoTODO]
  114. public XmlNameTable NameTable {
  115. get { throw new NotImplementedException (); }
  116. }
  117. [MonoTODO]
  118. public bool PreserveWhitespace {
  119. get { throw new NotImplementedException (); }
  120. }
  121. [MonoTODO]
  122. public XmlSchemaSet Schemas {
  123. get { throw new NotImplementedException (); }
  124. set { throw new NotImplementedException (); }
  125. }
  126. #endif // NET_2_0
  127. #endregion // Properies
  128. #region Methods
  129. #if NET_2_0
  130. [MonoTODO]
  131. public XPathChangeNavigator CreateChangeNavigator ()
  132. {
  133. throw new NotImplementedException ();
  134. }
  135. [MonoTODO]
  136. public XPathEditableNavigator CreateEditor ()
  137. {
  138. throw new NotImplementedException ();
  139. }
  140. [MonoTODO ("This code is only for compatibility.")]
  141. public XPathNavigator CreateNavigator ()
  142. {
  143. return document.CreateNavigator ();
  144. }
  145. [MonoTODO]
  146. public XmlWriter CreateWriter ()
  147. {
  148. throw new NotImplementedException ();
  149. }
  150. [MonoTODO]
  151. public virtual IList GetList ()
  152. {
  153. throw new NotImplementedException ();
  154. }
  155. [MonoTODO]
  156. public bool HasChanges ()
  157. {
  158. throw new NotImplementedException ();
  159. }
  160. [MonoTODO]
  161. public bool HasChanges (XmlChangeFilters changeFilter)
  162. {
  163. throw new NotImplementedException ();
  164. }
  165. [MonoTODO]
  166. public void Load (string xml)
  167. {
  168. throw new NotImplementedException ();
  169. // tree = new XPathDocumentTree (xmlReader);
  170. // if (acceptChangesOnLoad)
  171. // AcceptChanges ();
  172. }
  173. [MonoTODO]
  174. public void RejectChanges ()
  175. {
  176. throw new NotImplementedException ();
  177. }
  178. [MonoTODO ("Confirm writer settings etc.")]
  179. public void Save (Stream stream)
  180. {
  181. Save (new XmlTextWriter (stream, null));
  182. }
  183. [MonoTODO ("Confirm writer settings etc.")]
  184. public void Save (string filename)
  185. {
  186. using (XmlWriter w = new XmlTextWriter (filename, null)) {
  187. Save (w);
  188. }
  189. }
  190. [MonoTODO ("Confirm writer settings etc.")]
  191. public void Save (TextWriter writer)
  192. {
  193. Save (new XmlTextWriter (writer));
  194. }
  195. [MonoTODO]
  196. public void Save (XmlWriter writer)
  197. {
  198. throw new NotImplementedException ();
  199. }
  200. [MonoTODO]
  201. public XPathNodeIterator SelectNodes (string xpath)
  202. {
  203. return SelectNodes (xpath, null);
  204. }
  205. [MonoTODO]
  206. public XPathNodeIterator SelectNodes (XPathExpression expr)
  207. {
  208. throw new NotImplementedException ();
  209. }
  210. [MonoTODO]
  211. public XPathNodeIterator SelectNodes (string xpath ,IXmlNamespaceResolver nsResolver)
  212. {
  213. throw new NotImplementedException ();
  214. }
  215. [MonoTODO]
  216. public XPathEditableNavigator SelectSingleNode (string xpath)
  217. {
  218. return SelectSingleNode (xpath, null);
  219. }
  220. [MonoTODO]
  221. public XPathEditableNavigator SelectSingleNode (XPathExpression expr)
  222. {
  223. throw new NotImplementedException ();
  224. }
  225. [MonoTODO]
  226. public XPathEditableNavigator SelectSingleNode (string xpath ,IXmlNamespaceResolver nsResolver)
  227. {
  228. throw new NotImplementedException ();
  229. }
  230. #else // !NET_2_0
  231. public XPathNavigator CreateNavigator ()
  232. {
  233. return document.CreateNavigator ();
  234. }
  235. #endif
  236. #endregion
  237. }
  238. }