The Labs \ Source Viewer \ SSCLI \ System.Xml \ XmlEntity

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlEntity.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Xml
  16. {
  17.     using System.Diagnostics;
  18.    
  19.     // Represents a parsed or unparsed entity in the XML document.
  20.     public class XmlEntity : XmlNode
  21.     {
  22.         string publicId;
  23.         string systemId;
  24.         string notationName;
  25.         string name;
  26.         string unparsedReplacementStr;
  27.         string baseURI;
  28.         XmlLinkedNode lastChild;
  29.         private bool childrenFoliating;
  30.        
  31.         internal XmlEntity(string name, string strdata, string publicId, string systemId, string notationName, XmlDocument doc) : base(doc)
  32.         {
  33.             this.name = doc.NameTable.Add(name);
  34.             this.publicId = publicId;
  35.             this.systemId = systemId;
  36.             this.notationName = notationName;
  37.             this.unparsedReplacementStr = strdata;
  38.             this.childrenFoliating = false;
  39.         }
  40.        
  41.         // Throws an excption since an entity can not be cloned.
  42.         public override XmlNode CloneNode(bool deep)
  43.         {
  44.            
  45.             throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Cloning));
  46.         }
  47.        
  48.         //
  49.         // Microsoft extensions
  50.         //
  51.        
  52.         // Gets a value indicating whether the node is read-only.
  53.         public override bool IsReadOnly {
  54.                 // Make entities readonly
  55.             get { return true; }
  56.         }
  57.        
  58.        
  59.         // Gets the name of the node.
  60.         public override string Name {
  61.             get { return name; }
  62.         }
  63.        
  64.         // Gets the name of the node without the namespace prefix.
  65.         public override string LocalName {
  66.             get { return name; }
  67.         }
  68.        
  69.         // Gets the concatenated values of the entity node and all its children.
  70.         // The property is read-only and when tried to be set, exception will be thrown.
  71.         public override string InnerText {
  72.             get { return base.InnerText; }
  73.             set {
  74.                 throw new InvalidOperationException(Res.GetString(Res.Xdom_Ent_Innertext));
  75.             }
  76.         }
  77.        
  78.         internal override bool IsContainer {
  79.             get { return true; }
  80.         }
  81.        
  82.         internal override XmlLinkedNode LastNode {
  83.             get {
  84.                 if (lastChild == null && !childrenFoliating) {
  85.                     //expand the unparsedreplacementstring
  86.                     childrenFoliating = true;
  87.                     //wrap the replacement string with an element
  88.                     XmlLoader loader = new XmlLoader();
  89.                     loader.ExpandEntity(this);
  90.                 }
  91.                 return lastChild;
  92.             }
  93.             set { lastChild = value; }
  94.         }
  95.        
  96.         internal override bool IsValidChildType(XmlNodeType type)
  97.         {
  98.             return (type == XmlNodeType.Text || type == XmlNodeType.Element || type == XmlNodeType.ProcessingInstruction || type == XmlNodeType.Comment || type == XmlNodeType.CDATA || type == XmlNodeType.Whitespace || type == XmlNodeType.SignificantWhitespace || type == XmlNodeType.EntityReference);
  99.         }
  100.        
  101.         // Gets the type of the node.
  102.         public override XmlNodeType NodeType {
  103.             get { return XmlNodeType.Entity; }
  104.         }
  105.        
  106.         // Gets the value of the public identifier on the entity declaration.
  107.         public string PublicId {
  108.             get { return publicId; }
  109.         }
  110.        
  111.         // Gets the value of the system identifier on the entity declaration.
  112.         public string SystemId {
  113.             get { return systemId; }
  114.         }
  115.        
  116.         // Gets the name of the optional NDATA attribute on the
  117.         // entity declaration.
  118.         public string NotationName {
  119.             get { return notationName; }
  120.         }
  121.        
  122.         //Without override these two functions, we can't guarantee that WriteTo()/WriteContent() functions will never be called
  123.         public override string OuterXml {
  124.             get { return String.Empty; }
  125.         }
  126.        
  127.         public override string InnerXml {
  128.             get { return String.Empty; }
  129.             set {
  130.                 throw new InvalidOperationException(Res.GetString(Res.Xdom_Set_InnerXml));
  131.             }
  132.         }
  133.        
  134.         // Saves the node to the specified XmlWriter.
  135.         public override void WriteTo(XmlWriter w)
  136.         {
  137.         }
  138.        
  139.         // Saves all the children of the node to the specified XmlWriter.
  140.         public override void WriteContentTo(XmlWriter w)
  141.         {
  142.         }
  143.        
  144.         public override string BaseURI {
  145.             get { return baseURI; }
  146.         }
  147.        
  148.         internal void SetBaseURI(string inBaseURI)
  149.         {
  150.             baseURI = inBaseURI;
  151.         }
  152.     }
  153. }

Developer Fusion