2
0

XmlDeclaration.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // System.Xml.XmlDeclaration
  3. //
  4. // Author:
  5. // Duncan Mak ([email protected])
  6. //
  7. // (C) Ximian, Inc.
  8. using System;
  9. using System.Xml;
  10. namespace System.Xml
  11. {
  12. public class XmlDeclaration : XmlLinkedNode
  13. {
  14. string encoding = "UTF-8"; // defaults to UTF-8
  15. string standAlone;
  16. string version;
  17. protected internal XmlDeclaration (string version, string encoding,
  18. string standAlone, XmlDocument doc)
  19. : base (doc)
  20. {
  21. this.version = version;
  22. this.encoding = encoding;
  23. this.standAlone = standAlone;
  24. }
  25. public string Encoding {
  26. get {
  27. if (encoding == null)
  28. return String.Empty;
  29. else
  30. return encoding;
  31. }
  32. set { encoding = value ; } // Note: MS' doesn't check this string, should we?
  33. }
  34. public override string InnerText {
  35. get { return Value; }
  36. set { ParseInput (value); }
  37. }
  38. public override string LocalName {
  39. get { return "xml"; }
  40. }
  41. public override string Name {
  42. get { return "xml"; }
  43. }
  44. public override XmlNodeType NodeType {
  45. get { return XmlNodeType.XmlDeclaration; }
  46. }
  47. public string Standalone {
  48. get {
  49. if (standAlone == null)
  50. return String.Empty;
  51. else
  52. return standAlone;
  53. }
  54. set {
  55. if (value.ToUpper() == "YES")
  56. standAlone = "yes";
  57. if (value.ToUpper() == "NO")
  58. standAlone = "no";
  59. }
  60. }
  61. public override string Value {
  62. get { return String.Format ("version=\"{0}\" encoding=\"{1}\" standalone=\"{2}\"",
  63. Version, Encoding, Standalone); }
  64. set { ParseInput (value); }
  65. }
  66. public string Version {
  67. get { return version; }
  68. }
  69. public override XmlNode CloneNode (bool deep)
  70. {
  71. return new XmlDeclaration (Version, Encoding, standAlone, OwnerDocument);
  72. }
  73. public override void WriteContentTo (XmlWriter w)
  74. {
  75. // Nothing to do - no children.
  76. }
  77. [MonoTODO]
  78. public override void WriteTo (XmlWriter w)
  79. {
  80. if ((Standalone == String.Empty) || (Encoding == String.Empty))
  81. return;
  82. }
  83. void ParseInput (string input)
  84. {
  85. Encoding = input.Split (new char [] { ' ' }) [1].Split (new char [] { '=' }) [1];
  86. Standalone = input.Split (new char [] { ' ' }) [2].Split (new char [] { '=' }) [1];
  87. }
  88. }
  89. }