2003-11-02 Pedro Mart�nez Juli� <yoros@wanadoo.es>
[mono.git] / mcs / class / System.XML / System.Xml / XmlDocumentType.cs
1 //\r
2 // System.Xml.XmlDocumentType.cs\r
3 //\r
4 // Author: Duncan Mak (duncan@ximian.com)\r
5 //         Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)\r
6 //\r
7 // (C) Ximian, Inc.\r
8 //\r
9 using System;\r
10 using System.IO;\r
11 using System.Collections;\r
12 using Mono.Xml;\r
13 \r
14 namespace System.Xml\r
15 {\r
16         public class XmlDocumentType  : XmlLinkedNode\r
17         {\r
18                 // Fields\r
19 //              string name;            // name of the document type\r
20 //              string publicId;        // public identifier on the DOCTYPE\r
21 //              string systemId;        // system identifier on the DOCTYPE\r
22 //              string internalSubset;  // value of the DTD internal subset\r
23                 internal XmlNamedNodeMap entities;\r
24                 internal XmlNamedNodeMap notations;\r
25                 DTDObjectModel dtd;\r
26 \r
27                 // Constructor\r
28                 protected internal XmlDocumentType (string name, string publicId,\r
29                                                     string systemId, string internalSubset,\r
30                                                     XmlDocument doc)\r
31                         : base (doc)\r
32                 {\r
33                         XmlTextReader xtr = new XmlTextReader (BaseURI, new StringReader (""), doc.NameTable);\r
34                         xtr.XmlResolver = doc.Resolver;\r
35                         xtr.GenerateDTDObjectModel (name, publicId, systemId, internalSubset);\r
36                         this.dtd = xtr.DTD;\r
37 \r
38                         ImportFromDTD ();\r
39                 }\r
40 \r
41                 internal XmlDocumentType (DTDObjectModel dtd, XmlDocument doc)\r
42                         : base (doc)\r
43                 {\r
44                         this.dtd = dtd;\r
45                         ImportFromDTD ();\r
46                 }\r
47 \r
48                 private void ImportFromDTD ()\r
49                 {\r
50                         entities = new XmlNamedNodeMap (this);\r
51                         notations = new XmlNamedNodeMap (this);\r
52 \r
53                         foreach (DTDEntityDeclaration decl in DTD.EntityDecls.Values) {
54                                 XmlNode n = new XmlEntity (decl.Name, decl.NotationName,
55                                         decl.PublicId, decl.SystemId, OwnerDocument);
56                                 // FIXME: Value is more complex, similar to Attribute.
57                                 n.insertBeforeIntern (OwnerDocument.CreateTextNode (decl.LiteralEntityValue), null);
58                                 entities.Nodes.Add (n);
59                         }
60                         foreach (DTDNotationDeclaration decl in DTD.NotationDecls.Values) {
61                                 XmlNode n = new XmlNotation (decl.LocalName, decl.Prefix,
62                                         decl.PublicId, decl.SystemId, OwnerDocument);
63                                 notations.Nodes.Add (n);
64                         }
65                 }\r
66 \r
67                 // Properties\r
68                 internal DTDObjectModel DTD {\r
69                         get { return dtd; }\r
70                 }\r
71 \r
72                 public XmlNamedNodeMap Entities\r
73                 {\r
74                         get { return entities; }\r
75                 }\r
76                         \r
77                 public string InternalSubset\r
78                 {\r
79                         get { return dtd.InternalSubset; }\r
80                 }\r
81 \r
82                 public override bool IsReadOnly\r
83                 {\r
84                         get { return true; } // always return true\r
85                 }\r
86 \r
87                 public override string LocalName\r
88                 {\r
89                         get { return dtd.Name; }\r
90                 }\r
91 \r
92                 public override string Name\r
93                 {\r
94                         get { return dtd.Name; }\r
95                 }\r
96 \r
97                 public override XmlNodeType NodeType\r
98                 {\r
99                         get { return XmlNodeType.DocumentType; }\r
100                 }\r
101 \r
102                 public XmlNamedNodeMap Notations\r
103                 {\r
104                         get { return notations; }\r
105                 }\r
106 \r
107                 public string PublicId\r
108                 {\r
109                         get { return dtd.PublicId; }\r
110                 }\r
111 \r
112                 public string SystemId\r
113                 {\r
114                         get { return dtd.SystemId; }\r
115                 }\r
116 \r
117                 // Methods\r
118                 public override XmlNode CloneNode (bool deep)\r
119                 {\r
120                         // deep is ignored\r
121 //                      return new XmlDocumentType (Name, PublicId, SystemId,\r
122 //                                                  InternalSubset, OwnerDocument);\r
123                         return new XmlDocumentType (dtd, OwnerDocument);\r
124                 }\r
125                 \r
126                 public override void WriteContentTo (XmlWriter w)\r
127                 {\r
128                         // No effect\r
129                 }\r
130 \r
131                 public override void WriteTo (XmlWriter w)\r
132                 {\r
133                         w.WriteDocType (Name, PublicId, SystemId, InternalSubset);\r
134                 }\r
135         }\r
136 }\r