diff --git a/gxml/HTMLCollection.vala b/gxml/HTMLCollection.vala
index 3cb313c8306bd15b8dd9a33b0c934021cef33569..5004dba7c3e77a6ada2e8af49b44fb376c7f1251 100644
--- a/gxml/HTMLCollection.vala
+++ b/gxml/HTMLCollection.vala
@@ -1,7 +1,7 @@
/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/* GXmlDomCollections.vala
*
- * Copyright (C) 2016 Daniel Espinosa
+ * Copyright (C) 2016-2020 Daniel Espinosa
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -23,7 +23,7 @@
using Gee;
/**
- * DOM4 HTML Collection, powered by libxml2 library.
+ * DOM4 HTML Collection
*/
public class GXml.HTMLCollection : Gee.ArrayList,
GXml.DomHTMLCollection
diff --git a/gxml/HtmlDocument.vala b/gxml/HtmlDocument.vala
new file mode 100644
index 0000000000000000000000000000000000000000..4ca7cbab68b10d9cceff1f4fb95738607a7a473e
--- /dev/null
+++ b/gxml/HtmlDocument.vala
@@ -0,0 +1,45 @@
+/* HtmlDocument.vala
+ *
+ * Copyright (C) 2020 Daniel Espinosa
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see .
+ *
+ * Authors:
+ * Daniel Espinosa
+ */
+
+using Gee;
+
+/**
+ * DOM4 HTML Document
+ */
+public class GXml.HtmlDocument : GXml.Document
+{
+ [Description (nick="::ROOT")]
+ public GXml.DomElement html { get; set; }
+ construct {
+ html = (DomElement) GLib.Object.new (typeof (HtmlElement), "owner-document", this);
+ }
+}
+
+public class GXml.HtmlElement : GXml.Element
+{
+ construct {
+ try {
+ initialize ("html");
+ } catch (GLib.Error e) {
+ warning ("Error: %s", e.message);
+ }
+ }
+}
diff --git a/gxml/meson.build b/gxml/meson.build
index b87d5886f84432a4f633a10321ce2d42cf171f9d..c902cb7bb603cee573f8d8298f4d12648f5f1877 100644
--- a/gxml/meson.build
+++ b/gxml/meson.build
@@ -60,6 +60,7 @@ valasources = files ([
'HashPairedMap.vala',
'HashThreeMap.vala',
'HTMLCollection.vala',
+ 'HtmlDocument.vala',
'IXsdSchema.vala',
'LXPathObject.vala',
'Node.vala',
diff --git a/test/HtmlDocumentTest.vala b/test/HtmlDocumentTest.vala
new file mode 100644
index 0000000000000000000000000000000000000000..3eed57b0569b069da78daa99dc19a51da29cdd57
--- /dev/null
+++ b/test/HtmlDocumentTest.vala
@@ -0,0 +1,1529 @@
+/* HtmlDocumentTest.vala
+ *
+ * Copyright (C) 2011-2013 Richard Schwarting
+ * Copyright (C) 2011-2015 Daniel Espinosa
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see .
+ *
+ * Authors:
+ * Richard Schwarting
+ * Daniel Espinosa
+ */
+
+using GXml;
+
+public class XHtmlDocumentTest : GLib.Object {
+ public static int main (string[] args)
+ {
+ Test.init (ref args);
+ Test.add_func ("/gxml/HtmlDocument/api/element_id", () => {
+ try {
+ var doc = new XHtmlDocument.from_path (GXmlTestConfig.TEST_DIR+"/index.html");
+ Test.message ("Checking root element...");
+ assert (doc.document_element != null);
+ assert (doc.document_element.node_name.down () == "html".down ());
+ Test.message ("Searching for elemento with id 'user'...");
+ var n = doc.get_element_by_id ("user");
+ assert (n != null);
+ assert (n.node_name == "p");
+ assert (n is GXml.DomElement);
+ message (((GXml.DomElement) n).text_content);
+ assert (((GXml.DomElement) n).node_value == "");
+ } catch (GLib.Error e){
+ Test.message ("ERROR: "+e.message);
+ assert_not_reached ();
+ }
+ });
+ Test.add_func ("/gxml/HtmlDocument/api/element_class", () => {
+ try {
+ var doc = new XHtmlDocument.from_path (GXmlTestConfig.TEST_DIR+"/index.html");
+ Test.message ("Checking root element...");
+ assert (doc.document_element != null);
+ assert (doc.document_element.node_name.down () == "html".down ());
+ Test.message ("Searching for element with property class and value app...");
+ var np = doc.document_element.get_elements_by_property_value ("class","app");
+ assert (np != null);
+ assert (np.size == 2);
+ Test.message ("Searching for elemento with class 'app'...");
+ var l = doc.get_elements_by_class_name ("app");
+ assert (l != null);
+ assert (l.size == 2);
+ bool fdiv, fp;
+ fdiv = fp = false;
+ foreach (GXml.DomElement e in l) {
+ if (e.node_name == "div") fdiv = true;
+ if (e.node_name == "p") fp = true;
+ }
+ assert (fdiv);
+ assert (fp);
+ } catch (GLib.Error e){
+ Test.message ("ERROR: "+e.message);
+ assert_not_reached ();
+ }
+ });
+ Test.add_func ("/gxml/HtmlDocument/fom_string_doc", () => {
+ try {
+ var sdoc = "
+
+
+
+
+
+
+
+
+";
+ var doc = new XHtmlDocument.from_string_doc (sdoc);
+ assert (doc.document_element != null);
+ assert (doc.document_element.node_name.down () == "html".down ());
+ var ln = doc.document_element.get_elements_by_property_value ("type","text/javascript");
+ assert (ln != null);
+ assert (ln.size == 1);
+ var np = ln.item (0);
+ assert (np != null);
+ assert (np.node_name == "script");
+ var l = doc.get_elements_by_tag_name ("style");
+ assert (l != null);
+ assert (l.size == 1);
+ var sn = l.item (0);
+ assert (sn != null);
+ assert (sn.node_name == "style");
+ message (sn.child_nodes.length.to_string ());
+ assert (sn.child_nodes.length == 1);
+ message (doc.to_html ());
+ var s = doc.to_html ();
+ message (s);
+ assert ("style>\n * { color: red; }\n " in s);
+ } catch (GLib.Error e){
+ Test.message ("ERROR: "+e.message);
+ assert_not_reached ();
+ }
+ });
+ // Test.add_func ("/gxml/HtmlDocument/uri", () => {
+ // try {
+ // var f = GLib.File.new_for_uri ("http://www.omgubuntu.co.uk/2017/05/kde-neon-5-10-available-download-comes-plasma-5-10");
+ // DomDocument doc;
+ // doc = new XHtmlDocument.from_uri ("http://www.omgubuntu.co.uk/2017/05/kde-neon-5-10-available-download-comes-plasma-5-10");
+ // message ((doc as GDocument).to_string ());
+ // } catch (GLib.Error e){
+ // message ("ERROR: "+e.message);
+ // assert_not_reached ();
+ // }
+ // });
+ Test.add_func ("/gxml/HtmlDocument/element-by-property", () => {
+ var src = """
+
+
+
+
+Climat : la Chine est-elle le nouveau leader ? - France 24
+
Vous devez vérifier votre adresse email pour finaliser votre inscription. Consultez votre boite mail pour valider votre adresse en cliquant sur le lien figurant dans le mail de confirmation ou entrez à nouveau votre adresse email pour recevoir une nouvelle fois le mail de confirmation.
Merci de confirmer les informations ci-dessous avant de vous connecter
{* #socialRegistrationForm *} {* firstName *} {* lastName *} {* emailAddress *} {* displayName *} {* phone *} {* addressCity *} {* addressCountry *} En cliquant sur "Créer un compte", vous confirmez que vous acceptez nos conditions générales et que vous avez lu et approuvé la politique de protection de données personnelles.{* /socialRegistrationForm *}
C'est presque fini !
Merci de confirmer les informations ci-dessous avant de vous connecter Se connecter
{* #registrationForm *} {* firstName *} {* lastName *} {* emailAddress *} {* displayName *} {* phone *} {* addressCity *} {* addressCountry *} {* newPassword *} {* newPasswordConfirm *} En cliquant sur "Créer un compte", vous confirmez que vous acceptez nos conditions générales et que vous avez lu et approuvé la politique de protection de données personnelles.{* /registrationForm *}
Merci de votre inscription
Nous vous avons envoyé un email de confirmation à l'adresse suivante {* emailAddressData *}. Merci de consulter votre boîte de réception et de cliquer sur le lien pour activer votre compte..
+
Créer un nouveau mot de passe
Nous vous enverrons un lien pour créer un nouveau mot de passe