XmlDeclaration.cs 3.5 KB

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