62576f353957e0a8ab35c39f508999d08e271844
[mono.git] / mcs / class / System.XML / System.Xml / XmlDocumentType.cs
1 //
2 // System.Xml.XmlDocumentType.cs
3 //
4 // Author: Duncan Mak (duncan@ximian.com)
5 //         Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
6 //
7 // (C) Ximian, Inc.
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 using System;
31 using System.IO;
32 using System.Collections;
33 using Mono.Xml;
34
35 #if NET_2_0
36 using XmlTextReaderImpl = Mono.Xml2.XmlTextReader;
37 #else
38 using XmlTextReaderImpl = System.Xml.XmlTextReader;
39 #endif
40
41 namespace System.Xml
42 {
43         public class XmlDocumentType  : XmlLinkedNode
44         {
45                 // Fields
46                 internal XmlNamedNodeMap entities;
47                 internal XmlNamedNodeMap notations;
48                 DTDObjectModel dtd;
49
50                 // Constructor
51                 protected internal XmlDocumentType (string name, string publicId,
52                                                     string systemId, string internalSubset,
53                                                     XmlDocument doc)
54                         : base (doc)
55                 {
56                         XmlTextReaderImpl xtr = new XmlTextReaderImpl (BaseURI, new StringReader (""), doc.NameTable);
57                         xtr.XmlResolver = doc.Resolver;
58                         xtr.GenerateDTDObjectModel (name, publicId, systemId, internalSubset);
59                         this.dtd = xtr.DTD;
60
61                         ImportFromDTD ();
62                 }
63
64                 internal XmlDocumentType (DTDObjectModel dtd, XmlDocument doc)
65                         : base (doc)
66                 {
67                         this.dtd = dtd;
68                         ImportFromDTD ();
69                 }
70
71                 private void ImportFromDTD ()
72                 {
73                         entities = new XmlNamedNodeMap (this);
74                         notations = new XmlNamedNodeMap (this);
75
76                         foreach (DTDEntityDeclaration decl in DTD.EntityDecls.Values) {
77                                 XmlNode n = new XmlEntity (decl.Name, decl.NotationName,
78                                         decl.PublicId, decl.SystemId, OwnerDocument);
79                                 entities.SetNamedItem (n);
80                         }
81                         foreach (DTDNotationDeclaration decl in DTD.NotationDecls.Values) {
82                                 XmlNode n = new XmlNotation (decl.LocalName, decl.Prefix,
83                                         decl.PublicId, decl.SystemId, OwnerDocument);
84                                 notations.SetNamedItem (n);
85                         }
86                 }
87
88                 // Properties
89                 internal DTDObjectModel DTD {
90                         get { return dtd; }
91                 }
92
93                 public XmlNamedNodeMap Entities
94                 {
95                         get { return entities; }
96                 }
97                         
98                 public string InternalSubset
99                 {
100                         get { return dtd.InternalSubset; }
101                 }
102
103                 public override bool IsReadOnly
104                 {
105                         get { return true; } // always return true
106                 }
107
108                 public override string LocalName
109                 {
110                         get { return dtd.Name; }
111                 }
112
113                 public override string Name
114                 {
115                         get { return dtd.Name; }
116                 }
117
118                 public override XmlNodeType NodeType
119                 {
120                         get { return XmlNodeType.DocumentType; }
121                 }
122
123                 public XmlNamedNodeMap Notations
124                 {
125                         get { return notations; }
126                 }
127
128                 public string PublicId
129                 {
130                         get { return dtd.PublicId; }
131                 }
132
133                 public string SystemId
134                 {
135                         get { return dtd.SystemId; }
136                 }
137
138                 // Methods
139                 public override XmlNode CloneNode (bool deep)
140                 {
141                         // deep is ignored
142                         return new XmlDocumentType (dtd, OwnerDocument);
143                 }
144                 
145                 public override void WriteContentTo (XmlWriter w)
146                 {
147                         // No effect
148                 }
149
150                 public override void WriteTo (XmlWriter w)
151                 {
152                         w.WriteDocType (Name, PublicId, SystemId, InternalSubset);
153                 }
154         }
155 }