[gxml] Implemented GomTypeElement for writting
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Implemented GomTypeElement for writting
- Date: Tue, 24 Oct 2017 15:04:59 +0000 (UTC)
commit 13011b824f5cf7ea9534b6b62c4d32ee001cbdef
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Oct 23 15:17:18 2017 -0500
Implemented GomTypeElement for writting
gxml/GomDocument.vala | 13 ++++++-
gxml/XParser.vala | 78 +++++++++++++++++++++------------------------
test/GomDocumentTest.vala | 23 +++++++++++++
3 files changed, 70 insertions(+), 44 deletions(-)
---
diff --git a/gxml/GomDocument.vala b/gxml/GomDocument.vala
index 38c4b47..38ca907 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 bc0c215..017fbb9 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 f4ee855..f290bc0 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 ("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"
\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" in d.write_string ());
+ } catch (GLib.Error e) {
+ GLib.message ("Error: "+e.message);
+ assert_not_reached ();
+ }
+ });
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]