XmlDocument.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. //
  2. // System.Xml.XmlDocument
  3. //
  4. // Author:
  5. // Daniel Weber ([email protected])
  6. //
  7. // (C) 2001 Daniel Weber
  8. using System;
  9. using System.IO;
  10. using System.Xml.XPath;
  11. namespace System.Xml
  12. {
  13. public delegate void XmlNodeChangedEventHandler (XmlNodeChangedEventArgs args);
  14. public class XmlDocument : XmlNode
  15. {
  16. #region Constructors
  17. public XmlDocument () : base (null)
  18. {
  19. FOwnerDocument = this;
  20. }
  21. [MonoTODO]
  22. protected internal XmlDocument (XmlImplementation imp) : base (null)
  23. {
  24. throw new NotImplementedException ();
  25. }
  26. [MonoTODO]
  27. public XmlDocument (NameTable nt) : base (null)
  28. {
  29. throw new NotImplementedException ();
  30. }
  31. #endregion
  32. #region Events
  33. public event XmlNodeChangedEventHandler NodeChanged;
  34. public event XmlNodeChangedEventHandler NodeChanging;
  35. public event XmlNodeChangedEventHandler NodeInserted;
  36. public event XmlNodeChangedEventHandler NodeInserting;
  37. public event XmlNodeChangedEventHandler NodeRemoved;
  38. public event XmlNodeChangedEventHandler NodeRemoving;
  39. #endregion
  40. #region Properties
  41. [MonoTODO]
  42. public override string BaseURI {
  43. get {
  44. throw new NotImplementedException();
  45. }
  46. }
  47. public XmlElement DocumentElement {
  48. get {
  49. XmlNode node = FirstChild;
  50. while (node != null) {
  51. if (node is XmlElement)
  52. break;
  53. node = node.NextSibling;
  54. }
  55. return node != null ? node as XmlElement : null;
  56. }
  57. }
  58. [MonoTODO]
  59. public virtual XmlDocumentType DocumentType {
  60. get {
  61. throw new NotImplementedException();
  62. }
  63. }
  64. [MonoTODO]
  65. public XmlImplementation Implementation {
  66. get {
  67. throw new NotImplementedException();
  68. }
  69. }
  70. [MonoTODO]
  71. public override string InnerXml {
  72. get {
  73. throw new NotImplementedException();
  74. }
  75. set {
  76. throw new NotImplementedException();
  77. }
  78. }
  79. public override bool IsReadOnly {
  80. get {
  81. return false;
  82. }
  83. }
  84. public override string LocalName {
  85. get {
  86. return "#document";
  87. }
  88. }
  89. public override string Name {
  90. get {
  91. return "#document";
  92. }
  93. }
  94. [MonoTODO]
  95. public XmlNameTable NameTable {
  96. get {
  97. throw new NotImplementedException();
  98. }
  99. }
  100. public override XmlNodeType NodeType {
  101. get {
  102. return XmlNodeType.Document;
  103. }
  104. }
  105. public override XmlDocument OwnerDocument {
  106. get {
  107. return null;
  108. }
  109. }
  110. [MonoTODO]
  111. public bool PreserveWhitespace {
  112. get {
  113. throw new NotImplementedException();
  114. }
  115. set {
  116. throw new NotImplementedException();
  117. }
  118. }
  119. [MonoTODO]
  120. public XmlResolver XmlResolver {
  121. set {
  122. throw new NotImplementedException();
  123. }
  124. }
  125. #endregion
  126. #region Methods
  127. [MonoTODO]
  128. public override XmlNode CloneNode (bool deep)
  129. {
  130. throw new NotImplementedException ();
  131. }
  132. [MonoTODO]
  133. public XmlAttribute CreateAttribute (string name)
  134. {
  135. return new XmlAttribute (this, name, "");
  136. }
  137. [MonoTODO]
  138. public XmlAttribute CreateAttribute (string qualifiedName, string namespaceURI)
  139. {
  140. throw new NotImplementedException ();
  141. }
  142. [MonoTODO]
  143. public virtual XmlAttribute CreateAttribute (string prefix, string localName, string namespaceURI)
  144. {
  145. throw new NotImplementedException ();
  146. }
  147. [MonoTODO]
  148. public virtual XmlCDataSection CreateCDataSection (string data)
  149. {
  150. throw new NotImplementedException ();
  151. }
  152. [MonoTODO]
  153. public virtual XmlComment CreateComment (string data)
  154. {
  155. throw new NotImplementedException ();
  156. }
  157. [MonoTODO]
  158. protected internal virtual XmlAttribute CreateDefaultAttribute (string prefix, string localName, string namespaceURI)
  159. {
  160. throw new NotImplementedException ();
  161. }
  162. [MonoTODO]
  163. public virtual XmlDocumentFragment CreateDocumentFragment ()
  164. {
  165. throw new NotImplementedException ();
  166. }
  167. [MonoTODO]
  168. public virtual XmlDocumentType CreateDocumentType (
  169. string name,
  170. string publicId,
  171. string systemId,
  172. string internalSubset)
  173. {
  174. throw new NotImplementedException ();
  175. }
  176. [MonoTODO]
  177. public XmlElement CreateElement (string name)
  178. {
  179. throw new NotImplementedException ();
  180. }
  181. [MonoTODO]
  182. public XmlElement CreateElement (string qualifiedName, string namespaceURI)
  183. {
  184. throw new NotImplementedException ();
  185. }
  186. public virtual XmlElement CreateElement (
  187. string prefix,
  188. string localName,
  189. string namespaceURI)
  190. {
  191. return new XmlElement (prefix, localName, namespaceURI, this);
  192. }
  193. [MonoTODO]
  194. public virtual XmlEntityReference CreateEntityReference (string name)
  195. {
  196. throw new NotImplementedException ();
  197. }
  198. [MonoTODO]
  199. protected internal virtual XPathNavigator CreateNavigator (XmlNode node)
  200. {
  201. throw new NotImplementedException ();
  202. }
  203. [MonoTODO]
  204. public virtual XmlNode CreateNode (
  205. string nodeTypeString,
  206. string name,
  207. string namespaceURI)
  208. {
  209. throw new NotImplementedException ();
  210. }
  211. [MonoTODO]
  212. public virtual XmlNode CreateNode (
  213. XmlNodeType type,
  214. string name,
  215. string namespaceURI)
  216. {
  217. throw new NotImplementedException ();
  218. }
  219. [MonoTODO]
  220. public virtual XmlNode CreateNode (
  221. XmlNodeType type,
  222. string prefix,
  223. string name,
  224. string namespaceURI)
  225. {
  226. throw new NotImplementedException ();
  227. }
  228. [MonoTODO]
  229. public virtual XmlProcessingInstruction CreateProcessingInstruction (
  230. string target,
  231. string data)
  232. {
  233. throw new NotImplementedException();
  234. }
  235. [MonoTODO]
  236. public virtual XmlSignificantWhitespace CreateSignificantWhitespace (string text )
  237. {
  238. throw new NotImplementedException ();
  239. }
  240. public virtual XmlText CreateTextNode (string text)
  241. {
  242. return new XmlText (text, this);
  243. }
  244. [MonoTODO]
  245. public virtual XmlWhitespace CreateWhitespace (string text)
  246. {
  247. throw new NotImplementedException ();
  248. }
  249. [MonoTODO]
  250. public virtual XmlDeclaration CreateXmlDeclaration (
  251. string version,
  252. string encoding,
  253. string standalone)
  254. {
  255. throw new NotImplementedException();
  256. }
  257. [MonoTODO]
  258. public virtual XmlElement GetElementById (string elementId)
  259. {
  260. throw new NotImplementedException ();
  261. }
  262. [MonoTODO]
  263. public virtual XmlNodeList GetElementsByTagName (string name)
  264. {
  265. throw new NotImplementedException ();
  266. }
  267. [MonoTODO]
  268. public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
  269. {
  270. throw new NotImplementedException();
  271. }
  272. [MonoTODO]
  273. public virtual XmlNode ImportNode (XmlNode node, bool deep)
  274. {
  275. throw new NotImplementedException ();
  276. }
  277. [MonoTODO]
  278. public virtual void Load (Stream inStream)
  279. {
  280. throw new NotImplementedException ();
  281. }
  282. public virtual void Load (string filename)
  283. {
  284. XmlReader xmlReader = new XmlTextReader (new StreamReader (filename));
  285. Load (xmlReader);
  286. }
  287. [MonoTODO]
  288. public virtual void Load (TextReader txtReader)
  289. {
  290. throw new NotImplementedException ();
  291. }
  292. public virtual void Load (XmlReader xmlReader)
  293. {
  294. // Reset our document
  295. // For now this just means removing all our children but later this
  296. // may turn out o need to call a private method that resets other things
  297. // like properties we have, etc.
  298. RemoveAll ();
  299. XmlNode currentNode = this;
  300. while (xmlReader.Read ())
  301. {
  302. switch (xmlReader.NodeType) {
  303. case XmlNodeType.Element:
  304. XmlElement element = CreateElement (xmlReader.Name, xmlReader.LocalName, xmlReader.NamespaceURI);
  305. currentNode.AppendChild (element);
  306. // set the element's attributes.
  307. while (xmlReader.MoveToNextAttribute ())
  308. element.SetAttribute (xmlReader.Name, xmlReader.Value);
  309. // if this element isn't empty, push it onto our "stack".
  310. if (!xmlReader.IsEmptyElement)
  311. currentNode = element;
  312. break;
  313. case XmlNodeType.Text:
  314. XmlText text = CreateTextNode (xmlReader.Value);
  315. currentNode.AppendChild (text);
  316. break;
  317. case XmlNodeType.EndElement:
  318. currentNode = currentNode.ParentNode;
  319. break;
  320. }
  321. }
  322. }
  323. public virtual void LoadXml (string xml)
  324. {
  325. XmlReader xmlReader = new XmlTextReader (new StringReader (xml));
  326. Load (xmlReader);
  327. }
  328. [MonoTODO]
  329. public virtual XmlNode ReadNode(XmlReader reader)
  330. {
  331. throw new NotImplementedException ();
  332. }
  333. [MonoTODO]
  334. public virtual void Save(Stream outStream)
  335. {
  336. throw new NotImplementedException ();
  337. }
  338. [MonoTODO]
  339. public virtual void Save (string filename)
  340. {
  341. throw new NotImplementedException ();
  342. }
  343. [MonoTODO]
  344. public virtual void Save (TextWriter writer)
  345. {
  346. throw new NotImplementedException ();
  347. }
  348. [MonoTODO]
  349. public virtual void Save (XmlWriter writer)
  350. {
  351. throw new NotImplementedException ();
  352. }
  353. [MonoTODO]
  354. public override void WriteContentTo (XmlWriter xw)
  355. {
  356. throw new NotImplementedException ();
  357. }
  358. [MonoTODO]
  359. public override void WriteTo (XmlWriter w)
  360. {
  361. throw new NotImplementedException ();
  362. }
  363. internal void onNodeChanging(XmlNode node, XmlNode Parent)
  364. {
  365. if (NodeInserting != null)
  366. NodeChanging( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Change,
  367. node, Parent, Parent));
  368. }
  369. internal void onNodeChanged(XmlNode node, XmlNode Parent)
  370. {
  371. if (NodeChanged != null)
  372. NodeInserted( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Change,
  373. node, Parent, Parent));
  374. }
  375. internal void onNodeInserting(XmlNode node, XmlNode newParent)
  376. {
  377. if (NodeInserting != null)
  378. NodeInserting( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Insert,
  379. node, null, newParent));
  380. }
  381. internal void onNodeInserted(XmlNode node, XmlNode newParent)
  382. {
  383. if (NodeInserted != null)
  384. NodeInserted( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Insert,
  385. node, null, newParent));
  386. }
  387. internal void onNodeRemoving(XmlNode node, XmlNode oldParent)
  388. {
  389. if (NodeRemoving != null)
  390. NodeRemoving(new XmlNodeChangedEventArgs(XmlNodeChangedAction.Remove,
  391. node, oldParent, null));
  392. }
  393. internal void onNodeRemoved(XmlNode node, XmlNode oldParent)
  394. {
  395. if (NodeRemoved != null)
  396. NodeRemoved(new XmlNodeChangedEventArgs(XmlNodeChangedAction.Remove,
  397. node, oldParent, null));
  398. }
  399. #endregion
  400. }
  401. }