XmlNode.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. // -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2. //
  3. // System.Xml.XmlNode
  4. //
  5. // Author:
  6. // Daniel Weber ([email protected])
  7. //
  8. // (C) 2001 Daniel Weber
  9. using System;
  10. using System.Collections;
  11. namespace System.Xml
  12. {
  13. public abstract class XmlNode : ICloneable, IEnumerable, IXPathNavigable
  14. {
  15. //======= Private data members ==============================================
  16. protected XmlNodeList _childNodes;
  17. protected XmlNode FOwnerNode;
  18. // ICloneable
  19. /// <summary>
  20. /// Return a clone of this node
  21. /// </summary>
  22. /// <returns></returns>
  23. public virtual object Clone()
  24. {
  25. // TODO - implement XmlNode.Clone() as object
  26. throw new NotImplementedException("object XmlNode.Clone() not implmented");
  27. }
  28. // ============ Properties ============================
  29. /// <summary>
  30. /// Get the XmlAttributeCollection representing the attributes
  31. /// on the node type. Returns null if the node type is not XmlElement.
  32. /// </summary>
  33. public virtual XmlAttributeCollection Attributes
  34. {
  35. get
  36. {
  37. return null;
  38. }
  39. }
  40. /// <summary>
  41. /// Return the base Uniform Resource Indicator (URI) used to resolve
  42. /// this node, or String.Empty.
  43. /// </summary>
  44. public virtual string BaseURI
  45. {
  46. get
  47. {
  48. // TODO - implement XmlNode.BaseURI {get;}
  49. throw new NotImplementedException("XmlNode.BaseURI not implemented");
  50. }
  51. }
  52. /// <summary>
  53. /// Return all child nodes of this node. If there are no children,
  54. /// return an empty XmlNodeList;
  55. /// </summary>
  56. public virtual XmlNodeList ChildNodes
  57. {
  58. get
  59. {
  60. if (_childNodes == null)
  61. _childNodes = new XmlNodeListAsArrayList();
  62. return _childNodes;
  63. }
  64. }
  65. /// <summary>
  66. /// Return first child node as XmlNode or null
  67. /// if the node has no children
  68. /// </summary>
  69. public virtual XmlNode FirstChild
  70. {
  71. get
  72. {
  73. if (ChildNodes.Count == 0)
  74. return null;
  75. else
  76. return ChildNodes[0];
  77. }
  78. }
  79. /// <summary>
  80. /// Return true if the node has children
  81. /// </summary>
  82. public virtual bool HasChildNodes
  83. {
  84. get
  85. {
  86. if (_childNodes.Count == 0)
  87. return true;
  88. else
  89. return false;
  90. }
  91. }
  92. /// <summary>
  93. /// Get or Set the concatenated values of node and children
  94. /// </summary>
  95. public virtual string InnerText
  96. {
  97. get
  98. {
  99. // TODO - implement set InnerText()
  100. throw new NotImplementedException();
  101. }
  102. set
  103. {
  104. // TODO - implement set InnerText()
  105. throw new NotImplementedException();
  106. }
  107. }
  108. /// <summary>
  109. /// Get/Set the XML representing just the child nodes of this node
  110. /// </summary>
  111. public virtual string InnerXml
  112. {
  113. get
  114. {
  115. // TODO - implement set InnerXml()
  116. throw new NotImplementedException();
  117. }
  118. set
  119. {
  120. // TODO - implement set InnerXml()
  121. throw new NotImplementedException();
  122. }
  123. }
  124. /// <summary>
  125. /// Property Get - true if node is read-only
  126. /// </summary>
  127. public virtual bool IsReadOnly
  128. {
  129. get
  130. {
  131. // TODO - implement or decide to handle in subclass
  132. return true;
  133. }
  134. }
  135. /// <summary>
  136. /// Return the child element named [string]. Returns XmlElement
  137. /// Indexer for XmlNode class.
  138. /// </summary>
  139. [System.Runtime.CompilerServices.CSharp.IndexerName("Item")]
  140. public virtual XmlElement this [String index]
  141. {
  142. get
  143. {
  144. // TODO - implement XmlNode.Item(int?)
  145. throw new NotImplementedException();
  146. }
  147. }
  148. /// <summary>
  149. /// Get the last child node, or null if there are no nodes
  150. /// </summary>
  151. public virtual XmlNode LastChild
  152. {
  153. get
  154. {
  155. if (_childNodes.Count == 0)
  156. return null;
  157. else
  158. return _childNodes.Item(_childNodes.Count - 1);
  159. }
  160. }
  161. /// <summary>
  162. /// Returns the local name of the node with qualifiers removed
  163. /// LocalName of ns:elementName = "elementName"
  164. /// </summary>
  165. public abstract string LocalName {get;}
  166. /// <summary>
  167. /// Get the qualified node name
  168. /// derived classes must implement as behavior varies
  169. /// by tag type.
  170. /// </summary>
  171. public abstract string Name { get; }
  172. /// <summary>
  173. /// Get the namespace URI or String.Empty if none
  174. /// </summary>
  175. public virtual string NamespaceURI
  176. {
  177. get
  178. {
  179. // TODO - implement Namespace URI, or determine abstractness
  180. return String.Empty;
  181. }
  182. }
  183. /// <summary>
  184. /// Get the node immediatelly following this node, or null
  185. /// </summary>
  186. public virtual XmlNode NextSibling
  187. {
  188. get
  189. {
  190. // TODO - implement NextSibling
  191. throw new NotImplementedException();
  192. }
  193. }
  194. public virtual XmlNodeType NodeType
  195. {
  196. get
  197. {
  198. return XmlNodeType.None;
  199. }
  200. }
  201. /// <summary>
  202. /// Return the string representing this node and all it's children
  203. /// </summary>
  204. public virtual string OuterXml
  205. {
  206. get
  207. {
  208. // TODO - implement OuterXml {get;}
  209. throw new NotImplementedException();
  210. }
  211. }
  212. /// <summary>
  213. /// Return owning document.
  214. /// If this nodeType is a document, return null
  215. /// </summary>
  216. public virtual XmlDocument OwnerDocument
  217. {
  218. get
  219. {
  220. // TODO - implement OwnerDocument {get;}
  221. throw new NotImplementedException();
  222. }
  223. }
  224. /// <summary>
  225. /// Returns the parent node, or null
  226. /// Return value depends on superclass node type
  227. /// </summary>
  228. public virtual XmlNode ParentNode
  229. {
  230. get
  231. {
  232. // TODO - implement ParentNode[get;}
  233. throw new NotImplementedException();
  234. }
  235. }
  236. /// <summary>
  237. /// set/get the namespace prefix for this node, or
  238. /// string.empty if it does not exist
  239. /// </summary>
  240. public virtual string Prefix
  241. {
  242. get
  243. {
  244. // TODO - implement Prefix {get;}
  245. throw new NotImplementedException();
  246. }
  247. set
  248. {
  249. // TODO - implement Prefix {set;}
  250. throw new NotImplementedException();
  251. }
  252. }
  253. /// <summary>
  254. /// The preceding XmlNode or null
  255. /// </summary>
  256. public virtual XmlNode PreviousSibling {
  257. get
  258. {
  259. // TODO - implement PreviousSibling {get;}
  260. throw new NotImplementedException();
  261. }
  262. }
  263. /// <summary>
  264. /// Get/Set the value for this node
  265. /// </summary>
  266. public virtual string Value
  267. {
  268. get
  269. {
  270. // TODO - implement Value {get;}
  271. throw new NotImplementedException();
  272. }
  273. set
  274. {
  275. // TODO - implement Value {set;}
  276. throw new NotImplementedException();
  277. }
  278. }
  279. //======= Methods ==========================
  280. /// <summary>
  281. /// Appends the specified node to the end of the child node list
  282. /// </summary>
  283. /// <param name="newChild"></param>
  284. /// <returns></returns>
  285. public virtual XmlNode AppendChild (XmlNode newChild)
  286. {
  287. // TODO - implement AppendChild ();
  288. throw new NotImplementedException();
  289. }
  290. /// <summary>
  291. /// Return a clone of the node
  292. /// </summary>
  293. /// <param name="deep">Make copy of all children</param>
  294. /// <returns>Cloned node</returns>
  295. public abstract XmlNode CloneNode( bool deep);
  296. /// <summary>
  297. /// Return an XPathNavigator for navigating this node
  298. /// </summary>
  299. /// <returns></returns>
  300. public XPathNavigator CreateNavigator()
  301. {
  302. // TODO - implement CreateNavigator()
  303. throw new NotImplementedException();
  304. }
  305. /// <summary>
  306. /// Return true if self = obj || self.outerXml == obj.outerXml
  307. /// </summary>
  308. /// <param name="obj"></param>
  309. /// <returns></returns>
  310. public virtual bool Equals(object obj)
  311. {
  312. // TODO - implement Equals(obj)
  313. throw new NotImplementedException();
  314. }
  315. /// <summary>
  316. /// Return true if objA = objB || objA.outXml == objB.outerXml
  317. /// </summary>
  318. /// <param name="objA"></param>
  319. /// <param name="objB"></param>
  320. /// <returns></returns>
  321. public static bool Equals(object objA, object objB)
  322. {
  323. // TODO - implement equals(objA, objB)
  324. throw new NotImplementedException();
  325. }
  326. /// <summary>
  327. /// Provide support for "for each"
  328. /// </summary>
  329. /// <returns></returns>
  330. public IEnumerator GetEnumerator()
  331. {
  332. // TODO - implement GetEnumerator()
  333. throw new NotImplementedException();
  334. }
  335. /// <summary>
  336. /// Return a hash value for this node
  337. /// </summary>
  338. /// <returns></returns>
  339. public virtual int GetHashCode()
  340. {
  341. // TODO - implement GetHashCode()
  342. throw new NotImplementedException();
  343. }
  344. /// <summary>
  345. /// Look up the closest namespace for this node that is in scope for the given prefix
  346. /// </summary>
  347. /// <param name="prefix"></param>
  348. /// <returns>Namespace URI</returns>
  349. public virtual string GetNamespaceOfPrefix(string prefix)
  350. {
  351. // TODO - implement GetNamespaceOfPrefix()
  352. throw new NotImplementedException();
  353. }
  354. /// <summary>
  355. /// Get the closest xmlns declaration for the given namespace URI that is in scope.
  356. /// Returns the prefix defined in that declaration.
  357. /// </summary>
  358. /// <param name="namespaceURI"></param>
  359. /// <returns></returns>
  360. public virtual string GetPrefixOfNamespace(string namespaceURI)
  361. {
  362. // TODO - implement GetPrefixOfNamespace
  363. throw new NotImplementedException();
  364. }
  365. /// <summary>
  366. /// Get the type of the current node
  367. /// </summary>
  368. /// <returns></returns>
  369. public Type GetType()
  370. {
  371. // TODO - implement GetType()
  372. throw new NotImplementedException();
  373. }
  374. /// <summary>
  375. /// Insert newChild directlly after the reference node
  376. /// </summary>
  377. /// <param name="newChild"></param>
  378. /// <param name="refChild"></param>
  379. /// <returns></returns>
  380. public virtual XmlNode InsertAfter(XmlNode newChild, XmlNode refChild)
  381. {
  382. // TODO - implement InsertAfter();
  383. throw new NotImplementedException();
  384. }
  385. /// <summary>
  386. /// Insert newChild directly before the reference node.
  387. /// </summary>
  388. /// <param name="newChild"></param>
  389. /// <param name="refChild"></param>
  390. /// <returns></returns>
  391. public virtual XmlNode InsertBefore(XmlNode newChild, XmlNode refChild)
  392. {
  393. // TODO - implement InsertBefore()
  394. throw new NotImplementedException();
  395. }
  396. /// <summary>
  397. /// Put all nodes under this node in "normal" form
  398. /// Whatever that means...
  399. /// </summary>
  400. public virtual void Normalize()
  401. {
  402. // TODO - Implement Normalize()
  403. throw new NotImplementedException();
  404. }
  405. /// <summary>
  406. /// Add the specified child to the beginning of the child node list
  407. /// </summary>
  408. /// <param name="newChild">Node to add</param>
  409. /// <returns>The node added</returns>
  410. public virtual XmlNode PrependChild(XmlNode newChild)
  411. {
  412. //TODO - implement PrependChild(newChild)
  413. throw new NotImplementedException();
  414. }
  415. /// <summary>
  416. /// Remove all children and attributes
  417. /// </summary>
  418. public virtual void RemoveAll()
  419. {
  420. // TODO - implement RemoveAll()
  421. throw new NotImplementedException();
  422. }
  423. /// <summary>
  424. /// Remove specified child node
  425. /// </summary>
  426. /// <param name="oldChild"></param>
  427. /// <returns>Removed node</returns>
  428. public virtual XmlNode RemoveChild(XmlNode oldChild)
  429. {
  430. // TODO - implement RemoveChild(oldChild)
  431. throw new NotImplementedException();
  432. }
  433. /// <summary>
  434. /// Select a list of nodes matching the xpath
  435. /// </summary>
  436. /// <param name="xpath"></param>
  437. /// <returns>matching nodes</returns>
  438. public XmlNodeList SelectNodes( string xpath)
  439. {
  440. // TODO - imlement SelectNodes(xpath)
  441. throw new NotImplementedException();
  442. }
  443. /// <summary>
  444. /// Select a list of nodes matching the xpath. Any prefixes are resolved
  445. /// using the passed namespace manager
  446. /// </summary>
  447. /// <param name="xpath"></param>
  448. /// <param name="nsmgr"></param>
  449. /// <returns></returns>
  450. public XmlNodeList SelectNodes(string xpath, XmlNamespaceManager nsmgr)
  451. {
  452. // TODO - implement SelectNodes(xpath, nsmgr)
  453. throw new NotImplementedException();
  454. }
  455. /// <summary>
  456. /// Selects the first node that matches xpath
  457. /// </summary>
  458. /// <param name="?"></param>
  459. /// <returns></returns>
  460. public XmlNode SelectSingleNode(string xpatch)
  461. {
  462. // TODO - implement SelectSingeNode(xpath)
  463. throw new NotImplementedException();
  464. }
  465. /// <summary>
  466. /// Returns the first node that matches xpath
  467. /// Uses the passed namespace manager to resolve namespace URI's
  468. /// </summary>
  469. /// <param name="xpath"></param>
  470. /// <param name="nsmgr"></param>
  471. /// <returns></returns>
  472. public XmlNode SelectSingleNode(string xpath, XmlNamespaceManager nsmgr)
  473. {
  474. // Implement SelectSingleNode(xpath, nsmgr)
  475. throw new NotImplementedException();
  476. }
  477. /// <summary>
  478. /// Tests if the DOM implementation supports the passed feature
  479. /// </summary>
  480. /// <param name="feature"></param>
  481. /// <param name="version"></param>
  482. /// <returns></returns>
  483. public virtual bool Supports(string feature, string version)
  484. {
  485. //TODO - implement Supports(feature, version)
  486. throw new NotImplementedException();
  487. }
  488. /// <summary>
  489. /// Returns a string representation of the current node and it's children
  490. /// </summary>
  491. /// <returns></returns>
  492. public virtual string ToString()
  493. {
  494. // TODO - implement ToString()
  495. throw new NotImplementedException();
  496. }
  497. /// <summary>
  498. /// Saves all children of the current node to the passed writer
  499. /// </summary>
  500. /// <param name="w"></param>
  501. public abstract void WriteContentTo(XmlWriter w);
  502. /// <summary>
  503. /// Saves the current node to writer w
  504. /// </summary>
  505. /// <param name="w"></param>
  506. public abstract void WriteTo(XmlWriter w);
  507. //======= Internal methods ===============================================
  508. //======= Protected methods ==============================================
  509. //======= Private Methods ==================
  510. } // XmlNode
  511. } // using namespace System.Xml