XmlDocument.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. /// Get the local name of the node. For documents, returns "#document"
  105. /// </summary>
  106. public override string LocalName {
  107. get
  108. {
  109. return "#document";
  110. }
  111. }
  112. /// <summary>
  113. /// Get the qualified name of the node. For documents, returns "#document"
  114. /// </summary>
  115. public override string Name
  116. {
  117. get
  118. {
  119. return "#document";
  120. }
  121. }
  122. public XmlNameTable NameTable
  123. {
  124. get
  125. {
  126. // TODO - implement XmlDocument.NameTable {get;}
  127. throw new NotImplementedException("NameTable get not implemented");
  128. }
  129. }
  130. public override XmlNodeType NodeType
  131. {
  132. get
  133. {
  134. return XmlNodeType.Document;
  135. }
  136. }
  137. /// <summary>
  138. /// Returns OwnerDocument. For an XmlDocument, this property is always null.
  139. /// </summary>
  140. public override XmlDocument OwnerDocument
  141. {
  142. get
  143. {
  144. return null;
  145. }
  146. }
  147. public bool PreserveWhitespace
  148. {
  149. get
  150. {
  151. // TODO - implement XmlDocument.PreserveWhitespace {get;}
  152. throw new NotImplementedException("PreserveWhitespace get not implemented");
  153. }
  154. set
  155. {
  156. // TODO - implement XmlDocument.PreserveWhitespace {set;}
  157. throw new NotImplementedException("PreserveWhitespace set not implemented");
  158. }
  159. }
  160. public XmlResolver XmlResolver
  161. {
  162. set
  163. {
  164. // TODO - Finish/test XmlDocument.XmlResolver {set;}
  165. _resolver = value;
  166. }
  167. }
  168. // Public Methods
  169. //===========================================================================
  170. public override XmlNode CloneNode(bool deep)
  171. {
  172. // TODO - implement XmlDocument.CloneNode(bool)
  173. throw new NotImplementedException("CloneNode(bool) not implemented");
  174. }
  175. public XmlAttribute CreateAttribute(string name)
  176. {
  177. // TODO - implement XmlDocument.CreateAttribute(string name)
  178. throw new NotImplementedException("CreateAttribute(string name) not implemented");
  179. }
  180. public XmlAttribute CreateAttribute(string qualifiedName,string namespaceURI)
  181. {
  182. // TODO - implement XmlDocument.CreateAttribute(string, string)
  183. throw new NotImplementedException("CreateAttribute(string, string) not implemented");
  184. }
  185. public virtual XmlAttribute CreateAttribute(
  186. string prefix,
  187. string localName,
  188. string namespaceURI
  189. )
  190. {
  191. // TODO - implement XmlDocument.CreateAttribute(prefix, localName, namespaceURI)
  192. throw new NotImplementedException("CreateAttribute(prefix, localName, namespaceURI) not implemented");
  193. }
  194. public virtual XmlCDataSection CreateCDataSection(string data)
  195. {
  196. // TODO - implement XmlDocument.CreateCDataSection(string data)
  197. throw new NotImplementedException("CreateCDataSection(string data) not implemented");
  198. }
  199. public virtual XmlComment CreateComment(string data)
  200. {
  201. // TODO - implement XmlDocument.CreateComment(string data)
  202. throw new NotImplementedException("CreateComment(string data) not implemented");
  203. }
  204. public virtual XmlDocumentFragment CreateDocumentFragment()
  205. {
  206. // TODO - implement XmlDocument.CreateDocumentFragment
  207. throw new NotImplementedException("CreateDocumentFragment not implemented");
  208. }
  209. public virtual XmlDocumentType CreateDocumentType(
  210. string name,
  211. string publicId,
  212. string systemId,
  213. string internalSubset
  214. )
  215. {
  216. // TODO - implement XmlDocument.CreateDocumentType
  217. throw new NotImplementedException("CreateDocumentType not implemented");
  218. }
  219. public XmlElement CreateElement(string name)
  220. {
  221. // TODO - implement XmlDocument.CreateElement(string name)
  222. throw new NotImplementedException("CreateElement(string name) not implemented");
  223. }
  224. public XmlElement CreateElement(
  225. string qualifiedName,
  226. string namespaceURI
  227. )
  228. {
  229. // TODO - implement XmlDocument.CreateElement(string qualifiedName, string namespaceURI)
  230. throw new NotImplementedException("CreateElement(string qualifiedName, string namespaceURI) not implemented");
  231. }
  232. public virtual XmlElement CreateElement(
  233. string prefix,
  234. string localName,
  235. string namespaceURI
  236. )
  237. {
  238. // TODO - implement XmlDocument.CreateElement(prefix, localName, namespaceURI)
  239. throw new NotImplementedException("XmlDocument.CreateElement(prefix, localName, namespaceURI) not implemented.");
  240. }
  241. public virtual XmlEntityReference CreateEntityReference(string name)
  242. {
  243. // TODO - implement XmlDocument.CreateEntityReference
  244. throw new NotImplementedException("XmlDocument.CreateEntityReference not implemented.");
  245. }
  246. public virtual XmlNode CreateNode(
  247. string nodeTypeString,
  248. string name,
  249. string namespaceURI
  250. )
  251. {
  252. // TODO - implement XmlDocument.CreateNode(string, string, string)
  253. throw new NotImplementedException("XmlDocument.CreateNode not implemented.");
  254. }
  255. public virtual XmlNode CreateNode(
  256. XmlNodeType type,
  257. string name,
  258. string namespaceURI
  259. )
  260. {
  261. // TODO - implement XmlDocument.CreateNode(XmlNodeType, string, string)
  262. throw new NotImplementedException("XmlDocument.CreateNode not implemented.");
  263. }
  264. public virtual XmlNode CreateNode(
  265. XmlNodeType type,
  266. string prefix,
  267. string name,
  268. string namespaceURI
  269. )
  270. {
  271. // TODO - implement XmlDocument.CreateNode(XmlNodeType, string, string, string)
  272. throw new NotImplementedException("XmlDocument.CreateNode not implemented.");
  273. }
  274. public virtual XmlProcessingInstruction CreateProcessingInstruction(
  275. string target,
  276. string data
  277. )
  278. {
  279. // TODO - implement XmlDocument.CreateProcessingInstruction
  280. throw new NotImplementedException("XmlDocument.CreateProcessingInstruction not implemented.");
  281. }
  282. public virtual XmlSignificantWhitespace CreateSignificantWhitespace(string text )
  283. {
  284. // TODO - implement XmlDocument.CreateSignificantWhitespace
  285. throw new NotImplementedException("XmlDocument.CreateSignificantWhitespace not implemented.");
  286. }
  287. public virtual XmlText CreateTextNode(string text)
  288. {
  289. // TODO - implement XmlDocument.CreateTextNode
  290. throw new NotImplementedException("XmlDocument.CreateTextNode not implemented.");
  291. }
  292. public virtual XmlWhitespace CreateWhitespace(string text)
  293. {
  294. // TODO - implement XmlDocument.CreateWhitespace
  295. throw new NotImplementedException("XmlDocument.CreateWhitespace not implemented.");
  296. }
  297. public virtual XmlDeclaration CreateXmlDeclaration(
  298. string version,
  299. string encoding,
  300. string standalone
  301. )
  302. {
  303. // TODO - implement XmlDocument.CreateXmlDeclaration
  304. throw new NotImplementedException("XmlDocument.CreateXmlDeclaration not implemented.");
  305. }
  306. public virtual XmlElement GetElementById(string elementId)
  307. {
  308. // TODO - implement XmlDocument.GetElementById
  309. throw new NotImplementedException("XmlDocument.GetElementById not implemented.");
  310. }
  311. public virtual XmlNodeList GetElementsByTagName(string name)
  312. {
  313. // TODO - implement XmlDocument.GetElementsByTagName(name)
  314. throw new NotImplementedException("XmlDocument.GetElementsByTagName not implemented.");
  315. }
  316. public virtual XmlNodeList GetElementsByTagName(
  317. string localName,
  318. string namespaceURI
  319. )
  320. {
  321. // TODO - implement XmlDocument.GetElementsByTagName(localName, namespaceURI)
  322. throw new NotImplementedException("XmlDocument.GetElementsByTagName not implemented.");
  323. }
  324. public virtual XmlNode ImportNode(
  325. XmlNode node,
  326. bool deep
  327. )
  328. {
  329. // TODO - implement XmlDocument.ImportNode
  330. throw new NotImplementedException("XmlDocument.ImportNode not implemented.");
  331. }
  332. public virtual void Load(Stream inStream)
  333. {
  334. // TODO - implement XmlDocument.Load(Stream)
  335. throw new NotImplementedException("XmlDocument.Load(Stream) not implemented.");
  336. }
  337. public virtual void Load(string filename)
  338. {
  339. // TODO - implement XmlDocument.Load(string)
  340. throw new NotImplementedException("XmlDocument.Load(string) not implemented.");
  341. }
  342. public virtual void Load(TextReader txtReader)
  343. {
  344. // TODO - implement XmlDocument.Load(TextReader)
  345. throw new NotImplementedException("XmlDocument.Load(TextReader) not implemented.");
  346. }
  347. public virtual void Load(XmlReader reader)
  348. {
  349. // TODO - implement XmlDocument.Load(XmlReader)
  350. throw new NotImplementedException("XmlDocument.Load(XmlReader) not implemented.");
  351. }
  352. public virtual void LoadXml(string xml)
  353. {
  354. // TODO - implement XmlDocument.LoadXml
  355. throw new NotImplementedException("XmlDocument.LoadXml not implemented.");
  356. }
  357. public virtual void Save(Stream outStream)
  358. {
  359. // TODO - implement XmlDocument.Save(Stream)
  360. throw new NotImplementedException("XmlDocument.Save(Stream) not implemented.");
  361. }
  362. public virtual void Save(string filename)
  363. {
  364. // TODO - implement XmlDocument.Save(string)
  365. throw new NotImplementedException("XmlDocument.Save(string) not implemented.");
  366. }
  367. public virtual void Save(TextWriter writer)
  368. {
  369. // TODO - implement XmlDocument.Save(TextWriter)
  370. throw new NotImplementedException("XmlDocument.Save(TextWriter) not implemented.");
  371. }
  372. public virtual void Save(XmlWriter writer)
  373. {
  374. // TODO - implement XmlDocument.Save(XmlWriter)
  375. throw new NotImplementedException("XmlDocument.Save(XmlWriter) not implemented.");
  376. }
  377. public override void WriteContentTo(XmlWriter w)
  378. {
  379. // TODO - implement XmlDocument.WriteContentTo
  380. throw new NotImplementedException("XmlDocument.WriteContentTo not implemented.");
  381. }
  382. public override void WriteTo(XmlWriter w)
  383. {
  384. // TODO - implement XmlDocument.WriteTo
  385. throw new NotImplementedException("XmlDocument.WriteTo not implemented.");
  386. }
  387. // Internal functions
  388. //===========================================================================
  389. internal void onNodeChanging(XmlNode node, XmlNode Parent)
  390. {
  391. if (NodeInserting != null)
  392. NodeChanging( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Change,
  393. node, Parent, Parent));
  394. }
  395. internal void onNodeChanged(XmlNode node, XmlNode Parent)
  396. {
  397. if (NodeChanged != null)
  398. NodeInserted( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Change,
  399. node, Parent, Parent));
  400. }
  401. internal void onNodeInserting(XmlNode node, XmlNode newParent)
  402. {
  403. if (NodeInserting != null)
  404. NodeInserting( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Insert,
  405. node, null, newParent));
  406. }
  407. internal void onNodeInserted(XmlNode node, XmlNode newParent)
  408. {
  409. if (NodeInserted != null)
  410. NodeInserted( new XmlNodeChangedEventArgs(XmlNodeChangedAction.Insert,
  411. node, null, newParent));
  412. }
  413. internal void onNodeRemoving(XmlNode node, XmlNode oldParent)
  414. {
  415. if (NodeRemoving != null)
  416. NodeRemoving(new XmlNodeChangedEventArgs(XmlNodeChangedAction.Remove,
  417. node, oldParent, null));
  418. }
  419. internal void onNodeRemoved(XmlNode node, XmlNode oldParent)
  420. {
  421. if (NodeRemoved != null)
  422. NodeRemoved(new XmlNodeChangedEventArgs(XmlNodeChangedAction.Remove,
  423. node, oldParent, null));
  424. }
  425. // Constructors
  426. //===========================================================================
  427. public XmlDocument() : base(null)
  428. {
  429. }
  430. }
  431. }