diff --git a/gxml/GomDocument.vala b/gxml/GomDocument.vala index 38c4b47b77e1548433047f1790f26f16f8f3ec22..38ca907b7ec16b1715bbbd44cf1e03418c1fbf1c 100644 --- a/gxml/GomDocument.vala +++ b/gxml/GomDocument.vala @@ -393,7 +393,6 @@ public class GXml.GomImplementation : GLib.Object, GXml.DomImplementation { public class GXml.GomDocumentType : GXml.GomNode, - GXml.DomNode, GXml.DomChildNode, GXml.DomDocumentType { @@ -401,10 +400,20 @@ public class GXml.GomDocumentType : GXml.GomNode, protected string _public_id = ""; protected string _system_id = ""; - public new string name { get { return _name; } } + public string name { get { return _name; } } public string public_id { get { return _public_id; } } public string system_id { get { return _system_id; } } + construct { + _node_type = DomNode.NodeType.DOCUMENT_TYPE_NODE; + _local_name = "!DOCTYPE"; + } + public GomDocumentType (DomDocument doc, string name, string public_id, string system_id) { + _document = doc; + _name = name; + _public_id = public_id; + _system_id = system_id; + } public GomDocumentType.with_name (DomDocument doc, string name) { _document = doc; _name = name; diff --git a/gxml/XParser.vala b/gxml/XParser.vala index bc0c215cb5c503f83954eb83ef9e2acc4f1764ab..017fbb94b9a9a7c6a481822fc0979fdb3d37d1b7 100644 --- a/gxml/XParser.vala +++ b/gxml/XParser.vala @@ -533,28 +533,7 @@ public class GXml.XParser : Object, GXml.Parser { } // Non Elements foreach (GXml.DomNode n in node.child_nodes) { - if (n is GXml.DomElement) { - start_node (n); - size += tw.end_element (); - if (size > 1500) - tw.flush (); - } - if (n is GXml.DomText) { - size += tw.write_string (n.node_value); - if (size > 1500) - tw.flush (); - } - if (n is GXml.DomComment) { - size += tw.write_comment (n.node_value); - if (size > 1500) - tw.flush (); - } - if (n is GXml.DomProcessingInstruction) { - size += tw.write_pi ((n as DomProcessingInstruction).target, - (n as DomProcessingInstruction).data); - if (size > 1500) - tw.flush (); - } + write_node (n); } } @@ -655,28 +634,43 @@ public class GXml.XParser : Object, GXml.Parser { foreach (GXml.DomNode n in node.child_nodes) { Idle.add (start_node_async.callback); yield; - if (n is GXml.DomElement) { - start_node (n); - size += tw.end_element (); - if (size > 1500) - tw.flush (); - } - if (n is GXml.DomText) { - size += tw.write_string (n.node_value); + write_node (n); + } + } + private void write_node (DomNode n) { + if (tw == null) + throw new ParserError.INVALID_DATA_ERROR (_("Internal Error: No TextWriter initialized")); + int size = 0; + if (n is GXml.DomElement) { + start_node (n); + size += tw.end_element (); + if (size > 1500) + tw.flush (); + } + if (n is GXml.DomText) { + size += tw.write_string (n.node_value); + if (size > 1500) + tw.flush (); + } + if (n is GXml.DomComment) { + size += tw.write_comment (n.node_value); + if (size > 1500) + tw.flush (); + } + if (n is GXml.DomProcessingInstruction) { + size += tw.write_pi ((n as DomProcessingInstruction).target, + (n as DomProcessingInstruction).data); + if (size > 1500) + tw.flush (); + } + if (n is GXml.DomDocumentType) { + message ("Document Type:"); + size += tw.write_document_type ((n as DomDocumentType).name, + (n as DomDocumentType).public_id, + (n as DomDocumentType).system_id, + ""); if (size > 1500) tw.flush (); - } - if (n is GXml.DomComment) { - size += tw.write_comment (n.node_value); - if (size > 1500) - tw.flush (); - } - if (n is GXml.DomProcessingInstruction) { - size += tw.write_pi ((n as DomProcessingInstruction).target, - (n as DomProcessingInstruction).data); - if (size > 1500) - tw.flush (); - } } } } diff --git a/test/GomDocumentTest.vala b/test/GomDocumentTest.vala index f4ee855171ad4dcc3234be323a27d2a3a1e3f28d..f290bc09543983fa66d638cd4b1e63f87bdc7e8d 100644 --- a/test/GomDocumentTest.vala +++ b/test/GomDocumentTest.vala @@ -608,5 +608,28 @@ class GomDocumentTest : GXmlTest { assert_not_reached (); } }); + Test.add_func ("/gxml/gom-document/doc-type/create", () => { + try { + var d = new GomDocument (); + message ("Creating a DocumentType"); + var dt1 = new GXml.GomDocumentType (d, "svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"); + assert (dt1 is DomDocumentType); + assert (dt1.node_type == DomNode.NodeType.DOCUMENT_TYPE_NODE); + assert (dt1.node_name == "!DOCTYPE"); + assert (dt1.name == "svg"); + assert (dt1.public_id == "-//W3C//DTD SVG 1.1//EN"); + assert (dt1.system_id == "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"); + d.append_child (dt1); + assert (d.child_nodes.length == 1); + var r = d.create_element ("svg"); + d.append_child (r); + assert (d.child_nodes.length == 2); + message (d.write_string ()); + assert ("" in d.write_string ()); + } catch (GLib.Error e) { + GLib.message ("Error: "+e.message); + assert_not_reached (); + } + }); } }