2 // System.Xml.XmlEntityReference.cs
4 // Duncan Mak (duncan@ximian.com)
5 // Atsushi Enomoto (atsushi@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
8 // (C) 2004 Novell inc.
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
32 using System.Xml.XPath;
37 public class XmlEntityReference : XmlLinkedNode, IHasXmlChildNode
40 XmlLinkedNode lastLinkedChild;
43 protected internal XmlEntityReference (string name, XmlDocument doc)
46 // LAMESPEC: MS CreateNode() allows null node name.
47 XmlConvert.VerifyName (name);
48 entityName = doc.NameTable.Add (name);
53 XmlLinkedNode IHasXmlChildNode.LastLinkedChild {
54 get { return lastLinkedChild; }
55 set { lastLinkedChild = value; }
58 public override string BaseURI {
59 get { return base.BaseURI; }
62 private XmlEntity Entity {
64 XmlDocumentType doctype = OwnerDocument.DocumentType;
68 if (doctype.Entities == null)
71 return doctype.Entities.GetNamedItem (Name) as XmlEntity;
75 internal override string ChildrenBaseURI {
77 XmlEntity ent = Entity;
81 if (ent.SystemId == null || ent.SystemId.Length == 0)
84 if (ent.BaseURI == null || ent.BaseURI.Length == 0)
89 baseUri = new Uri (ent.BaseURI);
90 } catch (UriFormatException) {
93 XmlResolver resolver = OwnerDocument.Resolver;
95 return resolver.ResolveUri (baseUri, ent.SystemId).ToString ();
97 return new Uri (baseUri, ent.SystemId).ToString ();
101 public override bool IsReadOnly {
105 public override string LocalName {
106 get { return entityName; } // name of the entity referenced.
109 public override string Name {
110 get { return entityName; } // name of the entity referenced.
113 public override XmlNodeType NodeType {
114 get { return XmlNodeType.EntityReference; }
117 public override string Value {
118 get { return null; } // always return null here.
120 throw new XmlException ("entity reference cannot be set value.");
124 internal override XPathNodeType XPathNodeType {
126 return XPathNodeType.Text;
132 public override XmlNode CloneNode (bool deep)
135 // API docs: "The replacement text is not included." XmlNode.CloneNode
136 // "The replacement text is set when node is inserted." XmlEntityReference.CloneNode
138 return new XmlEntityReference (Name, OwnerDocument);
141 public override void WriteContentTo (XmlWriter w)
143 for (int i = 0; i < ChildNodes.Count; i++)
144 ChildNodes [i].WriteTo (w);
147 public override void WriteTo (XmlWriter w)
154 internal void SetReferencedEntityContent ()
156 if (FirstChild != null)
159 if (OwnerDocument.DocumentType == null)
162 XmlEntity ent = Entity;
164 InsertBefore (OwnerDocument.CreateTextNode (String.Empty), null, false, true);
166 for (int i = 0; i < ent.ChildNodes.Count; i++)
167 InsertBefore (ent.ChildNodes [i].CloneNode (true), null, false, true);