XmlDeclaration.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2. //
  3. // System.Xml.XmlDeclaration
  4. //
  5. // Author:
  6. // Daniel Weber ([email protected])
  7. //
  8. // (C) 2001 Daniel Weber
  9. using System;
  10. namespace System.Xml
  11. {
  12. /// <summary>
  13. ///
  14. /// </summary>
  15. public class XmlDeclaration : XmlNode
  16. {
  17. // Private data members
  18. private string Fencoding = "UTF-8";
  19. bool Fstandalone;
  20. // public properties
  21. /// <summary>
  22. /// Get/Set the encoding used for the document
  23. /// Typical values are "UTF-8", "UTF-16", "ISO-8859-nn" (where n is 0-9).
  24. /// If not defined, "UTF-8" is assumed.
  25. /// encoding is not case sensitive.
  26. /// </summary>
  27. public string Encoding
  28. {
  29. get
  30. {
  31. return Fencoding;
  32. }
  33. set
  34. {
  35. string val = value.ToUpper();
  36. if ( (val == "UTF-8") | ( val == "UTF-16") )
  37. {
  38. Fencoding = value;
  39. return;
  40. }
  41. else
  42. {
  43. if ( ( val.StartsWith( "ISO-8859-" ) ) & (val.Length == 10) )
  44. {
  45. try
  46. {
  47. int code = System.Convert.ToInt32( val.Substring(9,1) );
  48. Fencoding = value;
  49. }
  50. catch
  51. {
  52. throw new NotImplementedException("Encoding " + value + " is not supported");
  53. }
  54. }
  55. }
  56. }
  57. }
  58. /// <summary>
  59. /// Get the local name of the declaration. Returns "xml"
  60. /// </summary>
  61. public override string LocalName
  62. {
  63. get
  64. {
  65. return "xml";
  66. }
  67. }
  68. /// <summary>
  69. /// Get the name of the node. For XmlDeclaration, returns "xml".
  70. /// </summary>
  71. public override string Name
  72. {
  73. get
  74. {
  75. return "xml";
  76. }
  77. }
  78. /// <summary>
  79. /// Return the node type. For XmlDeclaration, returns XmlNodeType.XmlDeclaration.
  80. /// </summary>
  81. public override XmlNodeType NodeType
  82. {
  83. get
  84. {
  85. return XmlNodeType.XmlDeclaration;
  86. }
  87. }
  88. /// <summary>
  89. /// Get/Set the value of the standalone attribute.
  90. /// "yes" => no external DTD required.
  91. /// "no" => external data sources required.
  92. /// Silently fails if Set to invalid value.
  93. /// Not case sensitive.
  94. /// </summary>
  95. public string Standalone {
  96. get
  97. {
  98. if (Fstandalone)
  99. return "yes";
  100. else
  101. return "no";
  102. }
  103. set
  104. {
  105. if (value.ToUpper() == "YES")
  106. Fstandalone = true;
  107. if (value.ToUpper() == "NO")
  108. Fstandalone = false;
  109. }
  110. }
  111. /// <summary>
  112. /// Get the xml version of the file. Returns "1.0"
  113. /// </summary>
  114. public string Version
  115. {
  116. get
  117. {
  118. return "1.0";
  119. }
  120. }
  121. // Public Methods
  122. /// <summary>
  123. /// Overriden. Returns a cloned version of this node.
  124. /// Serves as a copy constructor. Duplicate node has no parent.
  125. /// </summary>
  126. /// <param name="deep">Create deep copy. N/A for XmlDeclaration.</param>
  127. /// <returns>Cloned node.</returns>
  128. public override XmlNode CloneNode(bool deep)
  129. {
  130. // TODO - implement XmlDeclration.CloneNode()
  131. throw new NotImplementedException("XmlDeclration.CloneNode() not implemented");
  132. }
  133. /// <summary>
  134. /// Save the children of this node to the passed XmlWriter. Since an XmlDeclaration has
  135. /// no children, this call has no effect.
  136. /// </summary>
  137. /// <param name="w"></param>
  138. public override void WriteContentTo(XmlWriter w)
  139. {
  140. // Nothing to do - no children.
  141. }
  142. /// <summary>
  143. /// Saves the node to the specified XmlWriter
  144. /// </summary>
  145. /// <param name="w">XmlWriter to writ to.</param>
  146. public override void WriteTo(XmlWriter w)
  147. {
  148. // TODO - implement XmlDeclration.WriteTo()
  149. throw new NotImplementedException("XmlDeclaration.WriteTo() not implemented");
  150. }
  151. // Constructors
  152. internal XmlDeclaration( XmlDocument aOwnerDoc) : base(aOwnerDoc)
  153. {
  154. }
  155. }
  156. }