1 //------------------------------------------------------------------------------
2 // <copyright file="XmlEntity.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
9 using System
.Diagnostics
;
11 // Represents a parsed or unparsed entity in the XML document.
12 public class XmlEntity
: XmlNode
{
17 String unparsedReplacementStr
;
19 XmlLinkedNode lastChild
;
20 private bool childrenFoliating
;
22 internal XmlEntity( String name
, String strdata
, string publicId
, string systemId
, String notationName
, XmlDocument doc
) : base( doc
) {
23 this.name
= doc
.NameTable
.Add(name
);
24 this.publicId
= publicId
;
25 this.systemId
= systemId
;
26 this.notationName
= notationName
;
27 this.unparsedReplacementStr
= strdata
;
28 this.childrenFoliating
= false;
31 // Throws an excption since an entity can not be cloned.
32 public override XmlNode
CloneNode(bool deep
) {
34 throw new InvalidOperationException(Res
.GetString(Res
.Xdom_Node_Cloning
));
38 // Microsoft extensions
41 // Gets a value indicating whether the node is read-only.
42 public override bool IsReadOnly
{
44 return true; // Make entities readonly
49 // Gets the name of the node.
50 public override string Name
{
54 // Gets the name of the node without the namespace prefix.
55 public override string LocalName
{
59 // Gets the concatenated values of the entity node and all its children.
60 // The property is read-only and when tried to be set, exception will be thrown.
61 public override string InnerText
{
62 get { return base.InnerText; }
64 throw new InvalidOperationException(Res
.GetString(Res
.Xdom_Ent_Innertext
));
68 internal override bool IsContainer
{
72 internal override XmlLinkedNode LastNode
{
74 if (lastChild
== null && !childrenFoliating
)
75 { //expand the unparsedreplacementstring
76 childrenFoliating
= true;
77 //wrap the replacement string with an element
78 XmlLoader loader
= new XmlLoader();
79 loader
.ExpandEntity(this);
83 set { lastChild = value;}
86 internal override bool IsValidChildType( XmlNodeType type
) {
87 return(type
== XmlNodeType
.Text
||
88 type
== XmlNodeType
.Element
||
89 type
== XmlNodeType
.ProcessingInstruction
||
90 type
== XmlNodeType
.Comment
||
91 type
== XmlNodeType
.CDATA
||
92 type
== XmlNodeType
.Whitespace
||
93 type
== XmlNodeType
.SignificantWhitespace
||
94 type
== XmlNodeType
.EntityReference
);
97 // Gets the type of the node.
98 public override XmlNodeType NodeType
{
99 get { return XmlNodeType.Entity;}
102 // Gets the value of the public identifier on the entity declaration.
103 public String PublicId
{
104 get { return publicId;}
107 // Gets the value of the system identifier on the entity declaration.
108 public String SystemId
{
109 get { return systemId;}
112 // Gets the name of the optional NDATA attribute on the
113 // entity declaration.
114 public String NotationName
{
115 get { return notationName;}
118 //Without override these two functions, we can't guarantee that WriteTo()/WriteContent() functions will never be called
119 public override String OuterXml
{
120 get { return String.Empty; }
123 public override String InnerXml
{
124 get { return String.Empty; }
125 set { throw new InvalidOperationException( Res.GetString(Res.Xdom_Set_InnerXml ) ); }
128 // Saves the node to the specified XmlWriter.
129 public override void WriteTo(XmlWriter w
) {
132 // Saves all the children of the node to the specified XmlWriter.
133 public override void WriteContentTo(XmlWriter w
) {
136 public override String BaseURI
{
137 get { return baseURI; }
140 internal void SetBaseURI( String inBaseURI
) {