From ccd455108d07e200aa011fdbbe60d07eb7144dc4 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 2 Oct 2010 15:15:06 +0200 Subject: [PATCH] Sorted input xml by id. --- configure.ac | 3 +- src/dbtransformer.c | 89 ++++++++++++++++++++++++++++++++++++++++++++ tests/test.db | Bin 7168 -> 7168 bytes tests/test.xml | 24 ++++++------ 4 files changed, 103 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 2866069..03b251a 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,8 @@ AC_PROG_RANLIB GTK_DOC_CHECK # Checks for libraries. -PKG_CHECK_MODULES(DBT, [libgda-4.0 >= 4.1.8]) +PKG_CHECK_MODULES(DBT, [libgda-4.0 >= 4.1.8 + libxslt >= 1.0.0]) AC_SUBST(DBT_CFLAGS) AC_SUBST(DBT_LIBS) diff --git a/src/dbtransformer.c b/src/dbtransformer.c index 0e54972..3619526 100644 --- a/src/dbtransformer.c +++ b/src/dbtransformer.c @@ -20,12 +20,36 @@ #include #endif +#include + #include #include + +#include +#include +#include + #include #include "libdbtransformer.h" +gchar *str_xslt_doc = +"\n" +"\n" +"\n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +"\n" +""; + static void dbt_class_init (DbtClass *class); static void dbt_init (Dbt *dbt); @@ -190,6 +214,65 @@ dbt_check_xml_root (xmlNodePtr xml_root) } } +static gboolean +dbt_sort_xml (Dbt *dbt) +{ + gboolean ret; + + DbtPrivate *priv; + + xmlDocPtr xslt_xdoc; + xsltStylesheetPtr xslt; + + ret = FALSE; + + priv = DBT_GET_PRIVATE (dbt); + + xmlSubstituteEntitiesDefault (1); + + xslt_xdoc = xmlParseMemory (str_xslt_doc, strlen (str_xslt_doc)); + if (xslt_xdoc == NULL) + { + g_warning ("Unable to parse the XSLT doc."); + return ret; + } + + xslt = xsltParseStylesheetDoc (xslt_xdoc); + if (xslt == NULL) + { + g_warning ("Unable to parse the XSLT doc."); + return ret; + } + + priv->xml_doc = xsltApplyStylesheet (xslt, priv->xml_doc, NULL); + if (priv->xml_doc == NULL) + { + g_warning ("Unable to apply the XSLT."); + return ret; + } + + priv->xml_root = xmlDocGetRootElement (priv->xml_doc); + if (priv->xml_root == NULL) + { + g_warning ("No root node after applied the XSLT."); + return ret; + } + + if (!dbt_check_xml_root (priv->xml_root)) + { + priv->xml_root = NULL; + + g_warning ("No root node after applied the XSLT."); + return ret; + } + + ret = TRUE; + + xsltFreeStylesheet (xslt); + + return ret; +} + /** * dbt_set_xml: * @dbt: @@ -210,6 +293,7 @@ dbt_set_xml (Dbt *dbt, xmlNodePtr xml_root) if (!dbt_check_xml_root (priv->xml_root)) { priv->xml_root = NULL; + return; } else { @@ -223,6 +307,8 @@ dbt_set_xml (Dbt *dbt, xmlNodePtr xml_root) g_warning ("Unable to include xml external files."); } } + + dbt_sort_xml (dbt); } /** * dbt_set_xml_from_filename: @@ -275,7 +361,10 @@ dbt_set_xml_from_filename (Dbt *dbt, const gchar *filename) if (!dbt_check_xml_root (priv->xml_root)) { priv->xml_root = NULL; + return; } + + dbt_sort_xml (dbt); } static gboolean diff --git a/tests/test.db b/tests/test.db index a61c14bdd724eae9870c1869037efd63015b5f5e..322af8aa49d930074467737ddbc8389516afd20f 100644 GIT binary patch delta 907 zcmZp$Xt0`e< zyyCR{qTIxi%=|pNMr~#mhNkGrQCzZ77O0b7aZ9l=GW}y<`nOq-KKc2GUz^%;05xSnO-n3A7FN3dcpXT@#SVgmQqGT z#z|q$q@2{e)N&M>%{j=`F~n6N#L>yeRRJbDS&KOinJ4RWNiiBv_Trkr!PZ#K$imQEJz0=bjLA@Ga)PwNWLxRp u$;UYbCf}1*nk2%qnT6#K^CA|Oi2*>Sz#nE2NC+@60%=w#W&>LDh8Y0o|3``d diff --git a/tests/test.xml b/tests/test.xml index 2abf1cd..944aef8 100644 --- a/tests/test.xml +++ b/tests/test.xml @@ -1,7 +1,7 @@ - + clients @@ -9,11 +9,11 @@ orders - newtable + newtablename - + + + newtable + newtablename + + + + newtable @@ -56,11 +63,4 @@ - - - newtable - newtablename - - - -- 2.49.0