[gxml] Added support for CDATA for TDocument.read_node()



commit e68981cb23d941f5aad16047d6c0ce117d817e42
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Mar 9 16:36:00 2016 -0600

    Added support for CDATA for TDocument.read_node()

 gxml/TDocument.vala     |   10 +++++++---
 test/TDocumentTest.vala |   18 +++++++++++++++++-
 test/t-read-test.xml    |    1 +
 3 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/gxml/TDocument.vala b/gxml/TDocument.vala
index eb8c8be..5f4cb51 100644
--- a/gxml/TDocument.vala
+++ b/gxml/TDocument.vala
@@ -502,14 +502,18 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
       GLib.message ("Type ATTRIBUTE");
       break;
     case Xml.ReaderType.TEXT:
-      GLib.message ("Type TEXT");
       var txtval = tr.read_string ();
+      GLib.message ("Type TEXT");
       GLib.message ("ReadNode: Text Node : '"+txtval+"'");
       n = node.document.create_text (txtval);
       node.children.add (n);
       break;
     case Xml.ReaderType.CDATA:
+      var cdval = tr.value ();
       GLib.message ("Type CDATA");
+      GLib.message ("ReadNode: CDATA Node : '"+cdval+"'");
+      n = node.document.create_cdata (cdval);
+      node.children.add (n);
       break;
     case Xml.ReaderType.ENTITY_REFERENCE:
       GLib.message ("Type ENTITY_REFERENCE");
@@ -518,16 +522,16 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
       GLib.message ("Type ENTITY");
       break;
     case Xml.ReaderType.PROCESSING_INSTRUCTION:
-      GLib.message ("Type PROCESSING_INSTRUCTION");
       var pit = tr.const_local_name ();
       var pival = tr.value ();
+      GLib.message ("Type PROCESSING_INSTRUCTION");
       GLib.message ("ReadNode: PI Node : '"+pit+"' : '"+pival+"'");
       n = node.document.create_pi (pit,pival);
       node.children.add (n);
       break;
     case Xml.ReaderType.COMMENT:
-      GLib.message ("Type COMMENT");
       var commval = tr.value ();
+      GLib.message ("Type COMMENT");
       GLib.message ("ReadNode: Comment Node : '"+commval+"'");
       n = node.document.create_comment (commval);
       node.children.add (n);
diff --git a/test/TDocumentTest.vala b/test/TDocumentTest.vala
index 490d622..b846cda 100644
--- a/test/TDocumentTest.vala
+++ b/test/TDocumentTest.vala
@@ -555,7 +555,7 @@ class TDocumentTest : GXmlTest {
                                GLib.message ("Doc:"+d.to_string ());
                        } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
                });
-               Test.add_func ("/gxml/t-document/read/PI", () => {
+               Test.add_func ("/gxml/t-document/read/pi", () => {
                        try {
                                var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
                                assert (f.query_exists ());
@@ -564,10 +564,12 @@ class TDocumentTest : GXmlTest {
                                assert (d.children[1] is GXml.ProcessingInstruction);
                                assert ((d.children[1] as GXml.ProcessingInstruction).target == "target");
                                assert (d.children[1].value == "Content in target id=\"something\"");
+#if DEBUG
                                GLib.message ("Children:"+d.root.children.size.to_string ());
                                foreach (GXml.Node n in d.root.children) {
                                        GLib.message ("Node name:"+n.name);
                                }
+#endif
                                assert (d.root.children.size == 5);
                                var p = (d.root.children[4]);
                                assert (p != null);
@@ -577,5 +579,19 @@ class TDocumentTest : GXmlTest {
                                GLib.message ("Doc:"+d.to_string ());
                        } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
                });
+               Test.add_func ("/gxml/t-document/read/cdata", () => {
+                       try {
+                               var f = GLib.File.new_for_path (GXmlTestConfig.TEST_DIR+"/t-read-test.xml");
+                               assert (f.query_exists ());
+                               var d = new TDocument ();
+                               TDocument.read_doc (d, f, null);
+                               assert (d.root.children.size == 6);
+                               var p = (d.root.children[5]);
+                               assert (p != null);
+                               assert (p is GXml.CDATA);
+                               assert ((p as GXml.CDATA).str == "<greeting>Hello, world!</greeting>");
+                               GLib.message ("Doc:"+d.to_string ());
+                       } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
+               });
        }
 }
diff --git a/test/t-read-test.xml b/test/t-read-test.xml
index f530e2d..b5e6bb5 100644
--- a/test/t-read-test.xml
+++ b/test/t-read-test.xml
@@ -20,4 +20,5 @@
   </Authors>
   <b:Book gxml:name="Thor"/>
   <?css href="http://www.gnome.org";?>
+  <![CDATA[<greeting>Hello, world!</greeting>]]>
 </Sentences>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]