[gxml] Added support for Processing Instructions



commit 07d8bf7d09c0e93625c37359864cac2104012569
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Mar 9 16:11:27 2016 -0600

    Added support for Processing Instructions
    
    * Fixed parse empty nodes in TDocument.read_node()

 gxml/TDocument.vala     |    8 ++++++++
 test/TDocumentTest.vala |   42 ++++++++++++++++++++++++++++++++++++------
 test/t-read-test.xml    |    2 ++
 3 files changed, 46 insertions(+), 6 deletions(-)
---
diff --git a/gxml/TDocument.vala b/gxml/TDocument.vala
index 4ca1513..eb8c8be 100644
--- a/gxml/TDocument.vala
+++ b/gxml/TDocument.vala
@@ -445,6 +445,8 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
       if (tr.read () != 1) return ReadType.STOP;
       break;
     case Xml.ReaderType.ELEMENT:
+      bool isempty = (tr.is_empty_element () == 1);
+      if (isempty) GLib.message ("Is Empty node:"+node.name);
       GLib.message ("ReadNode: Element: "+tr.const_local_name ());
       n = node.document.create_element (tr.const_local_name ());
       node.children.add (n);
@@ -492,6 +494,7 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
           }
         }
       }
+      if (isempty) return ReadType.CONTINUE;
       while (read_node (n, tr, rntfunc) == ReadType.CONTINUE);
       GLib.message ("Current Document: "+node.document.to_string ());
       break;
@@ -516,6 +519,11 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
       break;
     case Xml.ReaderType.PROCESSING_INSTRUCTION:
       GLib.message ("Type PROCESSING_INSTRUCTION");
+      var pit = tr.const_local_name ();
+      var pival = tr.value ();
+      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");
diff --git a/test/TDocumentTest.vala b/test/TDocumentTest.vala
index a998e03..490d622 100644
--- a/test/TDocumentTest.vala
+++ b/test/TDocumentTest.vala
@@ -484,14 +484,14 @@ class TDocumentTest : GXmlTest {
                                var a2 = s3.children[1];
                                assert (a2 != null);
                                assert (a2.children.size == 2);
-                               assert (a2.children[0].name == "Name");
-                               assert (a2.children[0].children.size == 1);
-                               assert (a2.children[0].children[0] is GXml.Text);
-                               assert (a2.children[0].children[0].value == "George");
-                               assert (a2.children[1].name == "Email");
+                               assert (a2.children[1].name == "Name");
                                assert (a2.children[1].children.size == 1);
                                assert (a2.children[1].children[0] is GXml.Text);
-                               assert (a2.children[1].children[0].value == "gweasley hogwarts co uk");
+                               assert (a2.children[1].children[0].value == "George");
+                               assert (a2.children[2].name == "Email");
+                               assert (a2.children[2].children.size == 1);
+                               assert (a2.children[2].children[0] is GXml.Text);
+                               assert (a2.children[2].children[0].value == "gweasley hogwarts co uk");
                        } catch (GLib.Error e) { GLib.message ("ERROR: "+e.message); assert_not_reached (); }
                });
                Test.add_func ("/gxml/t-document/read/namespace", () => {
@@ -544,6 +544,36 @@ class TDocumentTest : GXmlTest {
                                assert (f.query_exists ());
                                var d = new TDocument ();
                                TDocument.read_doc (d, f, null);
+                               assert (d.children[0] is GXml.Comment);
+                               assert (d.children[0].value == " Top Level Comment ");
+                               var a = d.root.children[2];
+                               assert (a.name == "Authors");
+                               var a1 = a.children[1];
+                               assert (a1.name == "Author");
+                               assert (a1.children[0] is GXml.Comment);
+                               assert (a1.children[0].value == " Inner comment");
+                               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", () => {
+                       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.children[1] is GXml.ProcessingInstruction);
+                               assert ((d.children[1] as GXml.ProcessingInstruction).target == "target");
+                               assert (d.children[1].value == "Content in target id=\"something\"");
+                               GLib.message ("Children:"+d.root.children.size.to_string ());
+                               foreach (GXml.Node n in d.root.children) {
+                                       GLib.message ("Node name:"+n.name);
+                               }
+                               assert (d.root.children.size == 5);
+                               var p = (d.root.children[4]);
+                               assert (p != null);
+                               assert (p is GXml.ProcessingInstruction);
+                               assert ((p as GXml.ProcessingInstruction).target == "css");
+                               assert ((p as GXml.ProcessingInstruction).value == 
"href=\"http://www.gnome.org\"";);
                                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 e80cf26..f530e2d 100644
--- a/test/t-read-test.xml
+++ b/test/t-read-test.xml
@@ -1,5 +1,6 @@
 <?xml version="1.0"?>
 <!-- Top Level Comment -->
+<?target Content in target id="something"?>
 <Sentences xmlns:gxml="http://wiki.gnome.org/GXml";
           xmlns:b="http://book.org/schema";
           audience="All">
@@ -18,4 +19,5 @@
     </Author>
   </Authors>
   <b:Book gxml:name="Thor"/>
+  <?css href="http://www.gnome.org";?>
 </Sentences>


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