2 // System.Xml.XmlEntity.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Atsushi Enomoto (atsushi@ximian.com)
9 // (C) 2004 Novell Inc.
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 public class XmlEntity
: XmlNode
, IHasXmlChildNode
40 internal XmlEntity (string name
, string NDATA
, string publicId
, string systemId
,
44 this.name
= doc
.NameTable
.Add (name
);
46 this.publicId
= publicId
;
47 this.systemId
= systemId
;
48 this.baseUri
= doc
.BaseURI
;
60 XmlLinkedNode lastLinkedChild
;
61 bool contentAlreadySet
;
67 XmlLinkedNode IHasXmlChildNode
.LastLinkedChild
{
69 if (lastLinkedChild
!= null)
70 return lastLinkedChild
;
71 if (!contentAlreadySet
) {
72 contentAlreadySet
= true;
75 return lastLinkedChild
;
77 set { lastLinkedChild = value; }
80 public override string BaseURI
{
81 get { return baseUri; }
84 public override string InnerText
{
85 get { return base.InnerText; }
86 set { throw new InvalidOperationException ("This operation is not supported."); }
89 public override string InnerXml
{
90 get { return base.InnerXml; }
91 set { throw new InvalidOperationException ("This operation is not supported."); }
94 public override bool IsReadOnly
{
95 get { return true; }
// always read-only.
98 public override string LocalName
{
102 public override string Name
{
106 public override XmlNodeType NodeType
{
107 get { return XmlNodeType.Entity; }
110 public string NotationName
{
119 public override string OuterXml
{
120 get { return String.Empty; }
123 public string PublicId
{
124 get { return publicId; }
127 public string SystemId
{
128 get { return systemId; }
134 public override XmlNode
CloneNode (bool deep
)
136 throw new InvalidOperationException ("This operation is not supported.");
139 public override void WriteContentTo (XmlWriter w
)
144 public override void WriteTo (XmlWriter w
)
149 void SetEntityContent ()
151 if (lastLinkedChild
!= null)
154 XmlDocumentType doctype
= OwnerDocument
.DocumentType
;
159 DTDEntityDeclaration decl
= doctype
.DTD
.EntityDecls
[name
];
163 XmlNamespaceManager nsmgr
= this.ConstructNamespaceManager ();
164 XmlParserContext ctx
= new XmlParserContext (OwnerDocument
.NameTable
, nsmgr
,
165 doctype
!= null ? doctype
.DTD
: null,
166 BaseURI
, XmlLang
, XmlSpace
, null);
167 XmlTextReader xmlReader
= new XmlTextReader (decl
.EntityValue
, XmlNodeType
.Element
, ctx
);
168 xmlReader
.XmlResolver
= OwnerDocument
.Resolver
;
171 XmlNode n
= OwnerDocument
.ReadNode (xmlReader
);
173 InsertBefore (n
, null, false, false);