XmlDocument.cs 13 KB

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