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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlDocumentType.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.    
  18.     using System.Xml.Schema;
  19.     using System.Diagnostics;
  20.    
  21.     // Contains information associated with the document type declaration.
  22.     public class XmlDocumentType : XmlLinkedNode
  23.     {
  24.         string name;
  25.         string publicId;
  26.         string systemId;
  27.         string internalSubset;
  28.         bool namespaces;
  29.         XmlNamedNodeMap entities;
  30.         XmlNamedNodeMap notations;
  31.        
  32.         // parsed DTD
  33.         SchemaInfo schemaInfo;
  34.        
  35.         protected internal XmlDocumentType(string name, string publicId, string systemId, string internalSubset, XmlDocument doc) : base(doc)
  36.         {
  37.             this.name = name;
  38.             this.publicId = publicId;
  39.             this.systemId = systemId;
  40.             this.namespaces = true;
  41.             this.internalSubset = internalSubset;
  42.             Debug.Assert(doc != null);
  43.             if (!doc.IsLoading) {
  44.                 doc.IsLoading = true;
  45.                 XmlLoader loader = new XmlLoader();
  46.                 loader.ParseDocumentType(this);
  47.                 //will edit notation nodes, etc.
  48.                 doc.IsLoading = false;
  49.             }
  50.         }
  51.        
  52.         // Gets the name of the node.
  53.         public override string Name {
  54.             get { return name; }
  55.         }
  56.        
  57.         // Gets the name of the current node without the namespace prefix.
  58.         public override string LocalName {
  59.             get { return name; }
  60.         }
  61.        
  62.         // Gets the type of the current node.
  63.         public override XmlNodeType NodeType {
  64.             get { return XmlNodeType.DocumentType; }
  65.         }
  66.        
  67.         // Creates a duplicate of this node.
  68.         public override XmlNode CloneNode(bool deep)
  69.         {
  70.             Debug.Assert(OwnerDocument != null);
  71.             return OwnerDocument.CreateDocumentType(name, publicId, systemId, internalSubset);
  72.         }
  73.        
  74.         //
  75.         // Microsoft extensions
  76.         //
  77.        
  78.         // Gets a value indicating whether the node is read-only.
  79.         public override bool IsReadOnly {
  80.                 // Make entities and notations readonly
  81.             get { return true; }
  82.         }
  83.        
  84.         // Gets the collection of XmlEntity nodes declared in the document type declaration.
  85.         public XmlNamedNodeMap Entities {
  86.             get {
  87.                 if (entities == null)
  88.                     entities = new XmlNamedNodeMap(this);
  89.                
  90.                 return entities;
  91.             }
  92.         }
  93.        
  94.         // Gets the collection of XmlNotation nodes present in the document type declaration.
  95.         public XmlNamedNodeMap Notations {
  96.             get {
  97.                 if (notations == null)
  98.                     notations = new XmlNamedNodeMap(this);
  99.                
  100.                 return notations;
  101.             }
  102.         }
  103.        
  104.         //
  105.         // DOM Level 2
  106.         //
  107.        
  108.         // Gets the value of the public identifier on the DOCTYPE declaration.
  109.         public string PublicId {
  110.             get { return publicId; }
  111.         }
  112.        
  113.         // Gets the value of
  114.         // the system identifier on the DOCTYPE declaration.
  115.         public string SystemId {
  116.             get { return systemId; }
  117.         }
  118.        
  119.         // Gets the entire value of the DTD internal subset
  120.         // on the DOCTYPE declaration.
  121.         public string InternalSubset {
  122.             get { return internalSubset; }
  123.         }
  124.        
  125.         internal bool ParseWithNamespaces {
  126.             get { return namespaces; }
  127.             set { namespaces = value; }
  128.         }
  129.        
  130.         // Saves the node to the specified XmlWriter.
  131.         public override void WriteTo(XmlWriter w)
  132.         {
  133.             w.WriteDocType(name, publicId, systemId, internalSubset);
  134.         }
  135.        
  136.         // Saves all the children of the node to the specified XmlWriter.
  137.         public override void WriteContentTo(XmlWriter w)
  138.         {
  139.             // Intentionally do nothing
  140.         }
  141.        
  142.         internal SchemaInfo DtdSchemaInfo {
  143.             get { return schemaInfo; }
  144.             set { schemaInfo = value; }
  145.         }
  146.     }
  147. }

Developer Fusion