XmlEntity.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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, IHasXmlChildNode
  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. XmlLinkedNode lastLinkedChild;
  55. #endregion
  56. #region Properties
  57. XmlLinkedNode IHasXmlChildNode.LastLinkedChild {
  58. get { return lastLinkedChild; }
  59. set { lastLinkedChild = value; }
  60. }
  61. public override string BaseURI {
  62. get { return baseUri; }
  63. }
  64. public override string InnerText {
  65. get { return base.InnerText; }
  66. set { throw new InvalidOperationException ("This operation is not supported."); }
  67. }
  68. public override string InnerXml {
  69. get { return base.InnerXml; }
  70. set { throw new InvalidOperationException ("This operation is not supported."); }
  71. }
  72. public override bool IsReadOnly {
  73. get { return true; } // always read-only.
  74. }
  75. public override string LocalName {
  76. get { return name; }
  77. }
  78. public override string Name {
  79. get { return name; }
  80. }
  81. public override XmlNodeType NodeType {
  82. get { return XmlNodeType.Entity; }
  83. }
  84. public string NotationName {
  85. get {
  86. if (NDATA == null)
  87. return null;
  88. else
  89. return NDATA;
  90. }
  91. }
  92. public override string OuterXml {
  93. get { return String.Empty; }
  94. }
  95. public string PublicId {
  96. get { return publicId; }
  97. }
  98. public string SystemId {
  99. get { return systemId; }
  100. }
  101. #endregion
  102. #region Methods
  103. public override XmlNode CloneNode (bool deep)
  104. {
  105. throw new InvalidOperationException ("This operation is not supported.");
  106. }
  107. public override void WriteContentTo (XmlWriter w)
  108. {
  109. // No effect.
  110. }
  111. public override void WriteTo (XmlWriter w)
  112. {
  113. // No effect.
  114. }
  115. internal void SetEntityContent ()
  116. {
  117. if (FirstChild != null)
  118. return;
  119. XmlDocumentType doctype = OwnerDocument.DocumentType;
  120. if (doctype == null)
  121. return;
  122. DTDEntityDeclaration decl = doctype.DTD.EntityDecls [name];
  123. if (decl == null)
  124. return;
  125. XmlNamespaceManager nsmgr = this.ConstructNamespaceManager ();
  126. XmlParserContext ctx = new XmlParserContext (OwnerDocument.NameTable, nsmgr,
  127. doctype != null ? doctype.DTD : null,
  128. BaseURI, XmlLang, XmlSpace, null);
  129. XmlTextReader xmlReader = new XmlTextReader (decl.EntityValue, XmlNodeType.Element, ctx);
  130. xmlReader.XmlResolver = OwnerDocument.Resolver;
  131. do {
  132. XmlNode n = OwnerDocument.ReadNode (xmlReader);
  133. if(n == null) break;
  134. InsertBefore (n, null, false, false);
  135. } while (true);
  136. }
  137. #endregion
  138. }
  139. }