XmlEntity.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // System.Xml.XmlEntity.cs
  3. //
  4. // Author:
  5. // Duncan Mak ([email protected])
  6. // Atsushi Enomoto ([email protected])
  7. //
  8. // (C) Ximian, Inc.
  9. // (C) 2004 Novell Inc.
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using Mono.Xml;
  32. namespace System.Xml
  33. {
  34. public class XmlEntity : XmlNode
  35. {
  36. #region Constructors
  37. internal XmlEntity (string name, string NDATA, string publicId, string systemId,
  38. XmlDocument doc)
  39. : base (doc)
  40. {
  41. this.name = doc.NameTable.Add (name);
  42. this.NDATA = NDATA;
  43. this.publicId = publicId;
  44. this.systemId = systemId;
  45. this.baseUri = doc.BaseURI;
  46. }
  47. #endregion
  48. #region Fields
  49. string name;
  50. string NDATA;
  51. string publicId;
  52. string systemId;
  53. string baseUri;
  54. #endregion
  55. #region Properties
  56. public override string BaseURI {
  57. get { return baseUri; }
  58. }
  59. public override string InnerText {
  60. get { return base.InnerText; }
  61. set { throw new InvalidOperationException ("This operation is not supported."); }
  62. }
  63. public override string InnerXml {
  64. get { return base.InnerXml; }
  65. set { throw new InvalidOperationException ("This operation is not supported."); }
  66. }
  67. public override bool IsReadOnly {
  68. get { return true; } // always read-only.
  69. }
  70. public override string LocalName {
  71. get { return name; }
  72. }
  73. public override string Name {
  74. get { return name; }
  75. }
  76. public override XmlNodeType NodeType {
  77. get { return XmlNodeType.Entity; }
  78. }
  79. public string NotationName {
  80. get {
  81. if (NDATA == null)
  82. return null;
  83. else
  84. return NDATA;
  85. }
  86. }
  87. public override string OuterXml {
  88. get { return String.Empty; }
  89. }
  90. public string PublicId {
  91. get { return publicId; }
  92. }
  93. public string SystemId {
  94. get { return systemId; }
  95. }
  96. #endregion
  97. #region Methods
  98. public override XmlNode CloneNode (bool deep)
  99. {
  100. throw new InvalidOperationException ("This operation is not supported.");
  101. }
  102. public override void WriteContentTo (XmlWriter w)
  103. {
  104. // No effect.
  105. }
  106. public override void WriteTo (XmlWriter w)
  107. {
  108. // No effect.
  109. }
  110. internal void SetEntityContent ()
  111. {
  112. if (FirstChild != null)
  113. return;
  114. XmlDocumentType doctype = OwnerDocument.DocumentType;
  115. if (doctype == null)
  116. return;
  117. DTDEntityDeclaration decl = doctype.DTD.EntityDecls [name];
  118. if (decl == null)
  119. return;
  120. XmlNamespaceManager nsmgr = this.ConstructNamespaceManager ();
  121. XmlParserContext ctx = new XmlParserContext (OwnerDocument.NameTable, nsmgr,
  122. doctype != null ? doctype.DTD : null,
  123. BaseURI, XmlLang, XmlSpace, null);
  124. XmlTextReader xmlReader = new XmlTextReader (decl.EntityValue, XmlNodeType.Element, ctx);
  125. xmlReader.XmlResolver = OwnerDocument.Resolver;
  126. do {
  127. XmlNode n = OwnerDocument.ReadNode (xmlReader);
  128. if(n == null) break;
  129. InsertBefore (n, null, false, false);
  130. } while (true);
  131. }
  132. #endregion
  133. }
  134. }