XmlComment.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. namespace System.Xml
  3. {
  4. /// <summary>
  5. ///
  6. /// </summary>
  7. ///
  8. /*
  9. * Section 2.5 of the XML spec says...
  10. [Definition: Comments may appear anywhere in a document outside other markup; in addition, they may appear within the document type declaration at places allowed by the grammar. They are not part of the document's character data; an XML processor may, but need not, make it possible for an application to retrieve the text of comments. For compatibility, the string "--" (double-hyphen) must not occur within comments.] Parameter entity references are not recognized within comments.
  11. Note that the grammar does not allow a comment ending in --->.
  12. Comment ::=   '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
  13. */
  14. public class XmlComment : XmlCharacterData
  15. {
  16. // Private data members
  17. // public properties
  18. public override string InnerText
  19. {
  20. get
  21. {
  22. // TODO - implement XmlComment.InnerText.get
  23. throw new NotImplementedException();
  24. }
  25. set
  26. {
  27. // TODO - implement XmlComment.InnerText.set
  28. throw new NotImplementedException();
  29. }
  30. }
  31. public override string LocalName
  32. {
  33. get
  34. {
  35. return "#comment";
  36. }
  37. }
  38. public override string Name
  39. {
  40. get
  41. {
  42. return "#comment";
  43. }
  44. }
  45. public override string Value
  46. {
  47. get
  48. {
  49. return Fvalue;
  50. }
  51. set
  52. {
  53. // TODO - Do our well-formedness checks on Value.set? (no)
  54. Fvalue = value;
  55. }
  56. }
  57. // Public Methods
  58. public override XmlNode CloneNode(bool deep)
  59. {
  60. // TODO - implement XmlComment.CloneNode(bool)
  61. throw new NotImplementedException();
  62. }
  63. public override void WriteContentTo(XmlWriter w)
  64. {
  65. // TODO - implement XmlComment.WriteContentTo(XmlWriter)
  66. throw new NotImplementedException();
  67. }
  68. public override void WriteTo(XmlWriter w)
  69. {
  70. // TODO - implement XmlComment.WriteTo(XmlWriter)
  71. throw new NotImplementedException();
  72. }
  73. // Internal methods
  74. /// <summary>
  75. /// Returns an exception object if passed text is not well-formed.
  76. /// Text is passed without introductory syntax elements.
  77. /// For comments, the leading "<!--" and trailing "-->" should be stripped.
  78. /// </summary>
  79. /// <param name="data"></param>
  80. /// <returns></returns>
  81. private XmlException wellFormed(string data, XmlInputSource src)
  82. {
  83. if (data.IndexOf("--") != -1)
  84. return new XmlException("Invalid characters (\"--\") in comment", src);
  85. if (data[0] == '-')
  86. return new XmlException("Invalid comment beginning (<!---)", src);
  87. if (data[data.Length - 1] == '-')
  88. return new XmlException("Invalid comment ending (--->)", src);
  89. return null;
  90. }
  91. // Constructors
  92. internal XmlComment(XmlDocument aOwner, string txt, XmlInputSource src) : base(aOwner)
  93. {
  94. XmlException e = wellFormed(txt, src);
  95. if ( e == null )
  96. {
  97. Fvalue = txt;
  98. }
  99. else
  100. throw e;
  101. }
  102. }
  103. }