XmlDocument.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. // -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2. //
  3. // System.Xml.XmlDocument
  4. //
  5. // Author:
  6. // Daniel Weber ([email protected])
  7. //
  8. // (C) 2001 Daniel Weber
  9. using System;
  10. using System.IO;
  11. namespace System.Xml
  12. {
  13. public delegate void XmlNodeChangedEventHandler (XmlNodeChangedEventArgs args);
  14. /// <summary>
  15. /// Abstract class XmlNodeList.
  16. /// </summary>
  17. public class XmlDocument : XmlNode
  18. {
  19. // Private data members
  20. XmlResolver _resolver = null;
  21. // Public events
  22. //===========================================================================
  23. public event XmlNodeChangedEventHandler NodeChanged;
  24. public event XmlNodeChangedEventHandler NodeChanging;
  25. public event XmlNodeChangedEventHandler NodeInserted;
  26. public event XmlNodeChangedEventHandler NodeInserting;
  27. public event XmlNodeChangedEventHandler NodeRemoved;
  28. public event XmlNodeChangedEventHandler NodeRemoving;
  29. // public properties
  30. /// <summary>
  31. /// Get the base URI for this document (the location from where the document was loaded)
  32. /// </summary>
  33. /// <example>If a document was loaded with doc.Load("c:\tmp\mydoc.xml"),
  34. /// then BaseURI would hold "c:\tmp\mydoc.xml"</example>
  35. public override string BaseURI
  36. {
  37. get
  38. {
  39. // TODO - implement XmlDocument.BaseURI {get;}
  40. throw new NotImplementedException("BaseURI.get not implemented");
  41. }
  42. }
  43. /// <summary>
  44. /// Get the root element for the document. If no root exists, null is returned.
  45. /// </summary>
  46. public XmlElement DocumentElement
  47. {
  48. get
  49. {
  50. // TODO - implement XmlDocument.Documentelement {get;}
  51. throw new NotImplementedException("XmlDocument.DocumentElement not implemented");
  52. }
  53. }
  54. /// <summary>
  55. /// Gets the node containing the DOCTYPE declaration.
  56. /// </summary>
  57. public virtual XmlDocumentType DocumentType
  58. {
  59. get
  60. {
  61. // TODO - implement XmlDocument.DocumentType
  62. throw new NotImplementedException("XmlDocument.DocumentType not implemented");
  63. }
  64. }
  65. /// <summary>
  66. /// Get the XmlImplemenation for the current document.
  67. /// </summary>
  68. public XmlImplementation Implementation
  69. {
  70. get
  71. {
  72. // TODO - implement XmlDocument.Implementation
  73. throw new NotImplementedException("Implementation not implemented");
  74. }
  75. }
  76. /// <summary>
  77. /// Get/Set the markup representing the children of the document.
  78. /// </summary>
  79. public override string InnerXml
  80. {
  81. get
  82. {
  83. // TODO - implement XmlDocument.InnerXml {get;}
  84. throw new NotImplementedException("InnerXml get not implemented");
  85. }
  86. set
  87. {
  88. // TODO - implement XmlDocument.InnerXml {set;}
  89. throw new NotImplementedException("InnerXml set not implemented");
  90. }
  91. }
  92. /// <summary>
  93. /// Get a value indicating if the document is read-only.
  94. /// </summary>
  95. public override bool IsReadOnly
  96. {
  97. get
  98. {
  99. // TODO - implement XmlDocument.IsReadOnly {get;}
  100. throw new NotImplementedException("IsReadOnly get not implemented");
  101. }
  102. }
  103. /// <summary>
  104. ///
  105. /// </summary>
  106. public override string LocalName {
  107. get
  108. {
  109. // TODO - implement XmlDocument.LocalName {get;}
  110. throw new NotImplementedException("LocalName get not implemented");
  111. }
  112. }
  113. /// <summary>
  114. ///
  115. /// </summary>
  116. public override string Name
  117. {
  118. get
  119. {
  120. // TODO - implement XmlDocument.Name {get;}
  121. throw new NotImplementedException("Name get not implemented");
  122. }
  123. }
  124. public XmlNameTable NameTable
  125. {
  126. get
  127. {
  128. // TODO - implement XmlDocument.NameTable {get;}
  129. throw new NotImplementedException("NameTable get not implemented");
  130. }
  131. }
  132. public override XmlNodeType NodeType
  133. {
  134. get
  135. {
  136. return XmlNodeType.Document;
  137. }
  138. }
  139. /// <summary>
  140. /// Returns OwnerDocument. For an XmlDocument, this property is always null.
  141. /// </summary>
  142. public override XmlDocument OwnerDocument
  143. {
  144. get
  145. {
  146. return null;
  147. }
  148. }
  149. public bool PreserveWhitespace
  150. {
  151. get
  152. {
  153. // TODO - implement XmlDocument.PreserveWhitespace {get;}
  154. throw new NotImplementedException("PreserveWhitespace get not implemented");
  155. }
  156. set
  157. {
  158. // TODO - implement XmlDocument.PreserveWhitespace {set;}
  159. throw new NotImplementedException("PreserveWhitespace set not implemented");
  160. }
  161. }
  162. public XmlResolver XmlResolver
  163. {
  164. set
  165. {
  166. // TODO - Finish/test XmlDocument.XmlResolver {set;}
  167. _resolver = value;
  168. }
  169. }
  170. // Public Methods
  171. //===========================================================================
  172. public override XmlNode CloneNode(bool deep)
  173. {
  174. // TODO - implement XmlDocument.CloneNode(bool)
  175. throw new NotImplementedException("CloneNode(bool) not implemented");
  176. }
  177. public XmlAttribute CreateAttribute(string name)
  178. {
  179. // TODO - implement XmlDocument.CreateAttribute(string name)
  180. throw new NotImplementedException("CreateAttribute(string name) not implemented");
  181. }
  182. public XmlAttribute CreateAttribute(string qualifiedName,string namespaceURI)
  183. {
  184. // TODO - implement XmlDocument.CreateAttribute(string, string)
  185. throw new NotImplementedException("CreateAttribute(string, string) not implemented");
  186. }
  187. public virtual XmlAttribute CreateAttribute(
  188. string prefix,
  189. string localName,
  190. string namespaceURI
  191. )
  192. {
  193. // TODO - implement XmlDocument.CreateAttribute(prefix, localName, namespaceURI)
  194. throw new NotImplementedException("CreateAttribute(prefix, localName, namespaceURI) not implemented");
  195. }
  196. public virtual XmlCDataSection CreateCDataSection(string data)
  197. {
  198. // TODO - implement XmlDocument.CreateCDataSection(string data)
  199. throw new NotImplementedException("CreateCDataSection(string data) not implemented");
  200. }
  201. public virtual XmlComment CreateComment(string data)
  202. {
  203. // TODO - implement XmlDocument.CreateComment(string data)
  204. throw new NotImplementedException("CreateComment(string data) not implemented");
  205. }
  206. public virtual XmlDocumentFragment CreateDocumentFragment()
  207. {
  208. // TODO - implement XmlDocument.CreateDocumentFragment
  209. throw new NotImplementedException("CreateDocumentFragment not implemented");
  210. }
  211. public virtual XmlDocumentType CreateDocumentType(
  212. string name,
  213. string publicId,
  214. string systemId,
  215. string internalSubset
  216. )
  217. {
  218. // TODO - implement XmlDocument.CreateDocumentType
  219. throw new NotImplementedException("CreateDocumentType not implemented");
  220. }
  221. public XmlElement CreateElement(string name)
  222. {
  223. // TODO - implement XmlDocument.CreateElement(string name)
  224. throw new NotImplementedException("CreateElement(string name) not implemented");
  225. }
  226. public XmlElement CreateElement(
  227. string qualifiedName,
  228. string namespaceURI
  229. )
  230. {
  231. // TODO - implement XmlDocument.CreateElement(string qualifiedName, string namespaceURI)
  232. throw new NotImplementedException("CreateElement(string qualifiedName, string namespaceURI) not implemented");
  233. }
  234. public virtual XmlElement CreateElement(
  235. string prefix,
  236. string localName,
  237. string namespaceURI
  238. )
  239. {
  240. // TODO - implement XmlDocument.CreateElement(prefix, localName, namespaceURI)
  241. throw new NotImplementedException("XmlDocument.CreateElement(prefix, localName, namespaceURI) not implemented.");
  242. }
  243. public virtual XmlEntityReference CreateEntityReference(string name)
  244. {
  245. // TODO - implement XmlDocument.CreateEntityReference
  246. throw new NotImplementedException("XmlDocument.CreateEntityReference not implemented.");
  247. }
  248. public virtual XmlNode CreateNode(
  249. string nodeTypeString,
  250. string name,
  251. string namespaceURI
  252. )
  253. {
  254. // TODO - implement XmlDocument.CreateNode(string, string, string)
  255. throw new NotImplementedException("XmlDocument.CreateNode not implemented.");
  256. }
  257. public virtual XmlNode CreateNode(
  258. XmlNodeType type,
  259. string name,
  260. string namespaceURI
  261. )
  262. {
  263. // TODO - implement XmlDocument.CreateNode(XmlNodeType, string, string)
  264. throw new NotImplementedException("XmlDocument.CreateNode not implemented.");
  265. }
  266. public virtual XmlNode CreateNode(
  267. XmlNodeType type,
  268. string prefix,
  269. string name,
  270. string namespaceURI
  271. )
  272. {
  273. // TODO - implement XmlDocument.CreateNode(XmlNodeType, string, string, string)
  274. throw new NotImplementedException("XmlDocument.CreateNode not implemented.");
  275. }
  276. public virtual XmlProcessingInstruction CreateProcessingInstruction(
  277. string target,
  278. string data
  279. )
  280. {
  281. // TODO - implement XmlDocument.CreateProcessingInstruction
  282. throw new NotImplementedException("XmlDocument.CreateProcessingInstruction not implemented.");
  283. }
  284. public virtual XmlSignificantWhitespace CreateSignificantWhitespace(string text )
  285. {
  286. // TODO - implement XmlDocument.CreateSignificantWhitespace
  287. throw new NotImplementedException("XmlDocument.CreateSignificantWhitespace not implemented.");
  288. }
  289. public virtual XmlText CreateTextNode(string text)
  290. {
  291. // TODO - implement XmlDocument.CreateTextNode
  292. throw new NotImplementedException("XmlDocument.CreateTextNode not implemented.");
  293. }
  294. public virtual XmlWhitespace CreateWhitespace(string text)
  295. {
  296. // TODO - implement XmlDocument.CreateWhitespace
  297. throw new NotImplementedException("XmlDocument.CreateWhitespace not implemented.");
  298. }
  299. public virtual XmlDeclaration CreateXmlDeclaration(
  300. string version,
  301. string encoding,
  302. string standalone
  303. )
  304. {
  305. // TODO - implement XmlDocument.CreateXmlDeclaration
  306. throw new NotImplementedException("XmlDocument.CreateXmlDeclaration not implemented.");
  307. }
  308. public virtual XmlElement GetElementById(string elementId)
  309. {
  310. // TODO - implement XmlDocument.GetElementById
  311. throw new NotImplementedException("XmlDocument.GetElementById not implemented.");
  312. }
  313. public virtual XmlNodeList GetElementsByTagName(string name)
  314. {
  315. // TODO - implement XmlDocument.GetElementsByTagName(name)
  316. throw new NotImplementedException("XmlDocument.GetElementsByTagName not implemented.");
  317. }
  318. public virtual XmlNodeList GetElementsByTagName(
  319. string localName,
  320. string namespaceURI
  321. )
  322. {
  323. // TODO - implement XmlDocument.GetElementsByTagName(localName, namespaceURI)
  324. throw new NotImplementedException("XmlDocument.GetElementsByTagName not implemented.");
  325. }
  326. public virtual XmlNode ImportNode(
  327. XmlNode node,
  328. bool deep
  329. )
  330. {
  331. // TODO - implement XmlDocument.ImportNode
  332. throw new NotImplementedException("XmlDocument.ImportNode not implemented.");
  333. }
  334. public virtual void Load(Stream inStream)
  335. {
  336. // TODO - implement XmlDocument.Load(Stream)
  337. throw new NotImplementedException("XmlDocument.Load(Stream) not implemented.");
  338. }
  339. public virtual void Load(string filename)
  340. {
  341. // TODO - implement XmlDocument.Load(string)
  342. throw new NotImplementedException("XmlDocument.Load(string) not implemented.");
  343. }
  344. public virtual void Load(TextReader txtReader)
  345. {
  346. // TODO - implement XmlDocument.Load(TextReader)
  347. throw new NotImplementedException("XmlDocument.Load(TextReader) not implemented.");
  348. }
  349. public virtual void Load(XmlReader reader)
  350. {
  351. // TODO - implement XmlDocument.Load(XmlReader)
  352. throw new NotImplementedException("XmlDocument.Load(XmlReader) not implemented.");
  353. }
  354. public virtual void LoadXml(string xml)
  355. {
  356. // TODO - implement XmlDocument.LoadXml
  357. throw new NotImplementedException("XmlDocument.LoadXml not implemented.");
  358. }
  359. public virtual void Save(Stream outStream)
  360. {
  361. // TODO - implement XmlDocument.Save(Stream)
  362. throw new NotImplementedException("XmlDocument.Save(Stream) not implemented.");
  363. }
  364. public virtual void Save(string filename)
  365. {
  366. // TODO - implement XmlDocument.Save(string)
  367. throw new NotImplementedException("XmlDocument.Save(string) not implemented.");
  368. }
  369. public virtual void Save(TextWriter writer)
  370. {
  371. // TODO - implement XmlDocument.Save(TextWriter)
  372. throw new NotImplementedException("XmlDocument.Save(TextWriter) not implemented.");
  373. }
  374. public virtual void Save(XmlWriter writer)
  375. {
  376. // TODO - implement XmlDocument.Save(XmlWriter)
  377. throw new NotImplementedException("XmlDocument.Save(XmlWriter) not implemented.");
  378. }
  379. public override void WriteContentTo(XmlWriter w)
  380. {
  381. // TODO - implement XmlDocument.WriteContentTo
  382. throw new NotImplementedException("XmlDocument.WriteContentTo not implemented.");
  383. }
  384. public override void WriteTo(XmlWriter w)
  385. {
  386. // TODO - implement XmlDocument.WriteTo
  387. throw new NotImplementedException("XmlDocument.WriteTo not implemented.");
  388. }
  389. // Internal functions
  390. //===========================================================================
  391. internal void onNodeChanging(XmlNode node, XmlNode Parent)
  392. {
  393. if (NodeInserting != null)
  394. NodeChanging( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Change,
  395. node, Parent, Parent));
  396. }
  397. internal void onNodeChanged(XmlNode node, XmlNode Parent)
  398. {
  399. if (NodeChanged != null)
  400. NodeInserted( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Change,
  401. node, Parent, Parent));
  402. }
  403. internal void onNodeInserting(XmlNode node, XmlNode newParent)
  404. {
  405. if (NodeInserting != null)
  406. NodeInserting( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Insert,
  407. node, null, newParent));
  408. }
  409. internal void onNodeInserted(XmlNode node, XmlNode newParent)
  410. {
  411. if (NodeInserted != null)
  412. NodeInserted( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Insert,
  413. node, null, newParent));
  414. }
  415. internal void onNodeRemoving(XmlNode node, XmlNode oldParent)
  416. {
  417. if (NodeRemoving != null)
  418. NodeRemoving(new XmlNodeChangedEventArgs(XmlNodeChangedAction.Remove,
  419. node, oldParent, null));
  420. }
  421. internal void onNodeRemoved(XmlNode node, XmlNode oldParent)
  422. {
  423. if (NodeRemoved != null)
  424. NodeRemoved(new XmlNodeChangedEventArgs(XmlNodeChangedAction.Remove,
  425. node, oldParent, null));
  426. }
  427. // Constructors
  428. //===========================================================================
  429. public XmlDocument() : base(null)
  430. {
  431. }
  432. }
  433. }