mscorlib(4.0.0.0) API with additions
XmlEntityReference.cs
1 using System.Collections;
2 
3 namespace System.Xml
4 {
7  {
8  private string name;
9 
10  private XmlLinkedNode lastChild;
11 
14  public override string Name => name;
15 
18  public override string LocalName => name;
19 
24  public override string Value
25  {
26  get
27  {
28  return null;
29  }
30  set
31  {
32  throw new InvalidOperationException(Res.GetString("Xdom_EntRef_SetVal"));
33  }
34  }
35 
38  public override XmlNodeType NodeType => XmlNodeType.EntityReference;
39 
43  public override bool IsReadOnly => true;
44 
45  internal override bool IsContainer => true;
46 
47  internal override XmlLinkedNode LastNode
48  {
49  get
50  {
51  return lastChild;
52  }
53  set
54  {
55  lastChild = value;
56  }
57  }
58 
61  public override string BaseURI => OwnerDocument.BaseURI;
62 
63  internal string ChildBaseURI
64  {
65  get
66  {
67  XmlEntity entityNode = OwnerDocument.GetEntityNode(name);
68  if (entityNode != null)
69  {
70  if (entityNode.SystemId != null && entityNode.SystemId.Length > 0)
71  {
72  return ConstructBaseURI(entityNode.BaseURI, entityNode.SystemId);
73  }
74  return entityNode.BaseURI;
75  }
76  return string.Empty;
77  }
78  }
79 
83  protected internal XmlEntityReference(string name, XmlDocument doc)
84  : base(doc)
85  {
86  if (!doc.IsLoading && name.Length > 0 && name[0] == '#')
87  {
88  throw new ArgumentException(Res.GetString("Xdom_InvalidCharacter_EntityReference"));
89  }
90  this.name = doc.NameTable.Add(name);
91  doc.fEntRefNodesPresent = true;
92  }
93 
98  public override XmlNode CloneNode(bool deep)
99  {
101  }
102 
103  internal override void SetParent(XmlNode node)
104  {
105  base.SetParent(node);
106  if (LastNode == null && node != null && node != OwnerDocument)
107  {
108  XmlLoader xmlLoader = new XmlLoader();
109  xmlLoader.ExpandEntityReference(this);
110  }
111  }
112 
113  internal override void SetParentForLoad(XmlNode node)
114  {
115  SetParent(node);
116  }
117 
118  internal override bool IsValidChildType(XmlNodeType type)
119  {
120  switch (type)
121  {
122  case XmlNodeType.Element:
123  case XmlNodeType.Text:
124  case XmlNodeType.CDATA:
125  case XmlNodeType.EntityReference:
126  case XmlNodeType.ProcessingInstruction:
127  case XmlNodeType.Comment:
128  case XmlNodeType.Whitespace:
129  case XmlNodeType.SignificantWhitespace:
130  return true;
131  default:
132  return false;
133  }
134  }
135 
138  public override void WriteTo(XmlWriter w)
139  {
140  w.WriteEntityRef(name);
141  }
142 
145  public override void WriteContentTo(XmlWriter w)
146  {
147  IEnumerator enumerator = GetEnumerator();
148  try
149  {
150  while (enumerator.MoveNext())
151  {
152  XmlNode xmlNode = (XmlNode)enumerator.Current;
153  xmlNode.WriteTo(w);
154  }
155  }
156  finally
157  {
158  IDisposable disposable = enumerator as IDisposable;
159  if (disposable != null)
160  {
161  disposable.Dispose();
162  }
163  }
164  }
165 
166  private string ConstructBaseURI(string baseURI, string systemId)
167  {
168  if (baseURI == null)
169  {
170  return systemId;
171  }
172  int num = baseURI.LastIndexOf('/') + 1;
173  string str = baseURI;
174  if (num > 0 && num < baseURI.Length)
175  {
176  str = baseURI.Substring(0, num);
177  }
178  else if (num == 0)
179  {
180  str += "\\";
181  }
182  return str + systemId.Replace('\\', '/');
183  }
184  }
185 }
Represents an XML document. You can use this class to load, validate, edit, add, and position XML in ...
Definition: XmlDocument.cs:13
override XmlNode CloneNode(bool deep)
Creates a duplicate of this node.
override void WriteTo(XmlWriter w)
Saves the node to the specified T:System.Xml.XmlWriter.
IEnumerator GetEnumerator()
Get an enumerator that iterates through the child nodes in the current node.
Definition: XmlNode.cs:1111
bool MoveNext()
Advances the enumerator to the next element of the collection.
XmlNameTable NameTable
Gets the T:System.Xml.XmlNameTable associated with this implementation.
Definition: XmlDocument.cs:230
override string BaseURI
Gets the base URI of the current node.
Definition: XmlDocument.cs:367
virtual XmlDocument OwnerDocument
Gets the T:System.Xml.XmlDocument to which this node belongs.
Definition: XmlNode.cs:104
override bool IsReadOnly
Gets a value indicating whether the node is read-only.
abstract void WriteTo(XmlWriter w)
Saves the current node to the specified T:System.Xml.XmlWriter, when overridden in a derived class.
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
Definition: IDisposable.cs:8
Definition: __Canon.cs:3
Represents an entity reference node.
internal XmlEntityReference(string name, XmlDocument doc)
Initializes a new instance of the T:System.Xml.XmlEntityReference class.
XmlNodeType
Specifies the type of node.
Definition: XmlNodeType.cs:5
Represents a writer that provides a fast, non-cached, forward-only way to generate streams or files t...
Definition: XmlWriter.cs:12
Represents an entity declaration, such as <!ENTITY... >.
Definition: XmlEntity.cs:4
Gets the node immediately preceding or following this node.
Definition: XmlLinkedNode.cs:4
object Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:15
abstract void WriteEntityRef(string name)
When overridden in a derived class, writes out an entity reference as &name;.
The exception that is thrown when one of the arguments provided to a method is not valid.
override string Value
Gets or sets the value of the node.
abstract string Add(char[] array, int offset, int length)
When overridden in a derived class, atomizes the specified string and adds it to the XmlNameTable.
virtual XmlEntityReference CreateEntityReference(string name)
Creates an T:System.Xml.XmlEntityReference with the specified name.
Definition: XmlDocument.cs:914
override void WriteContentTo(XmlWriter w)
Saves all the children of the node to the specified T:System.Xml.XmlWriter.
override string BaseURI
Gets the base Uniform Resource Identifier (URI) of the current node.
Definition: XmlEntity.cs:107
The exception that is thrown when a method call is invalid for the object's current state.
override XmlNodeType NodeType
Gets the type of the node.
override string BaseURI
Gets the base Uniform Resource Identifier (URI) of the current node.
void Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resourc...
override string Name
Gets the name of the node.
Represents a single node in the XML document.
Definition: XmlNode.cs:13
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
string SystemId
Gets the value of the system identifier on the entity declaration.
Definition: XmlEntity.cs:80
override string LocalName
Gets the local name of the node.