2003-07-15 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / System.Xml / XmlDocumentType.cs
index 9c8287bb0fcdfdf3435a88fc807765811f74ba2c..3447351cb30808ebcf904c3a00f60d015c7536ca 100644 (file)
@@ -8,6 +8,7 @@
 //\r
 using System;\r
 using System.Collections;\r
+using Mono.Xml;\r
 \r
 namespace System.Xml\r
 {\r
@@ -20,8 +21,7 @@ namespace System.Xml
                string internalSubset;  // value of the DTD internal subset\r
                internal XmlNamedNodeMap entities;\r
                internal XmlNamedNodeMap notations;\r
-               internal Hashtable elementDecls;\r
-               internal Hashtable attListDecls;\r
+               DTDObjectModel DTD;\r
 \r
                // Constructor\r
                protected internal XmlDocumentType (string name, string publicId,\r
@@ -33,12 +33,44 @@ namespace System.Xml
                        this.publicId = publicId;\r
                        this.systemId = systemId;\r
                        this.internalSubset = internalSubset;\r
+\r
+                       XmlTextReader xtr = new XmlTextReader ("", XmlNodeType.Document, null);\r
+                       xtr.GenerateDTDObjectModel (name, publicId, systemId, internalSubset);\r
+                       this.DTD = xtr.DTD;\r
+\r
+                       ImportFromDTD ();\r
+               }\r
+\r
+               internal XmlDocumentType (XmlTextReader reader, XmlDocument doc)\r
+                       : base (doc)\r
+               {\r
+                       this.name = reader.Name;\r
+                       this.publicId = reader ["PUBLIC"];\r
+                       this.systemId = reader ["SYSTEM"];\r
+                       this.internalSubset = reader.Value;\r
+                       this.DTD = reader.DTD;\r
+\r
+                       ImportFromDTD ();\r
+               }\r
+\r
+               private void ImportFromDTD ()\r
+               {\r
                        entities = new XmlNamedNodeMap (this);\r
                        notations = new XmlNamedNodeMap (this);\r
-                       elementDecls = new Hashtable ();\r
-                       attListDecls = new Hashtable ();\r
-               }\r
 \r
+                       foreach (DTDEntityDeclaration decl in DTD.EntityDecls.Values) {
+                               XmlNode n = new XmlEntity (decl.Name, decl.NotationName,
+                                       decl.PublicId, decl.SystemId, OwnerDocument);
+                               // FIXME: Value is more complex, similar to Attribute.
+                               n.insertBeforeIntern (OwnerDocument.CreateTextNode (decl.EntityValue), null);
+                               entities.Nodes.Add (n);
+                       }
+                       foreach (DTDNotationDeclaration decl in DTD.NotationDecls.Values) {
+                               XmlNode n = new XmlNotation (decl.LocalName, decl.Prefix,
+                                       decl.PublicId, decl.SystemId, OwnerDocument);
+                               notations.Nodes.Add (n);
+                       }
+               }\r
 \r
                // Properties\r
                public XmlNamedNodeMap Entities\r