In the file backend, there exists a write_namespace_decl() function that is #ifdef-ed out, as well as some calls to it that place the appropriate declarations in the tag. I've taken the liberty of enabling that function, and of modifying the write_namespace_decl() calls to include (hopefully) all the namespaces that can exist in the file. I also modified the file version check to look at "<gnc-v2" instead of "<gnc-v2>".
The benefits of this move may not be immediately visible to all. First off, the change allows the file to work either with or without the decls, although saving the file will of course include the decls. Now, the benefit comes when the file is parsed by an XSLT parser. The two XSLT parsers on Linux that I've tried are Saxon and Xalan, and both fail due to the namespaces not being declared. Given the availability of XSLT parsers, coupled with the desire to export the XML file to different formats, it seems only natural to include the namespace declarations within the top element below root. What are the benefits of XSLT? Well, let me tell you...XSLT provides an easy and rapid way to successfully transform a well-formed XML document into a variety of other formats without programatically changing Gnucash (other than the namespace decls, of course ;) I was mucking about with a question by someone to see if there was a way to get a list of Customers out of the file. Well, with XSLT, there is. I'm able to pull a list of customers by name with no effort on my part--simply run the file and stylesheet through the parser, and voila! you have your list. In my case (with my one customer), I set up HTML as the output style and got this (yes, it's raw html). <html xmlns:cust="http://www.gnucash.org/xml/cust" xmlns:gnc="http://www.gnucash.org/xml/gnc"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Finances File</title> </head> <body> <h1>Customers</h1> <p>My Widgets</p> </body> </html> The point is, much could be done with XSLT to provide the hotly desired export capabilities without affecting the internals of Gnucash one single solitary bit. Heck, someone could write a stylesheet that transforms the Gnucash file to an OO spreadsheet, or worse, to an Excel spreadsheet (the doc spec is only what, 100 pages? =P)!! but it depends on having the well-formed XML (which, for the XSLT parser means the namespaces are declared *shrug*). Anyhow, the attached patch accomplishes the namespace part. It would make life easier/safer for XSLT writers, because then they wouldn't have to edit the Gnucash XML file by hand to add the declarations... The attached patch is against HEAD, but it applied cleanly (with an offset) to 1.8.x CVS, too. Thanks, -- Matthew Vanecek perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);' ******************************************************************************** For 93 million miles, there is nothing between the sun and my shadow except me. I'm always getting in the way of something...
Index: src/backend/file/io-gncxml-v2.c =================================================================== RCS file: /home/cvs/cvsroot/gnucash/src/backend/file/io-gncxml-v2.c,v retrieving revision 1.36 diff -u -r1.36 io-gncxml-v2.c --- src/backend/file/io-gncxml-v2.c 30 Jul 2003 05:17:37 -0000 1.36 +++ src/backend/file/io-gncxml-v2.c 9 Aug 2003 02:59:16 -0000 @@ -1042,12 +1042,13 @@ } while ( (schedXactions = schedXactions->next) ); } -#if 0 +#if 1 static void write_namespace_decl (FILE *out, const char *namespace) { g_return_if_fail (namespace); - fprintf(out, " xmlns:%s=\"\"", namespace); + fprintf(out, "\n xmlns:%s=\"http://www.gnucash.org/XML/%s\"", + namespace, namespace); } #endif @@ -1056,16 +1057,21 @@ { fprintf(out, "<?xml version=\"1.0\"?>\n"); fprintf(out, "<" GNC_V2_STRING); - /* + write_namespace_decl (out, "cd"); + write_namespace_decl (out, "book"); write_namespace_decl (out, "gnc"); - write_namespace_decl (out, "act"); write_namespace_decl (out, "cmdty"); write_namespace_decl (out, "trn"); - write_namespace_decl (out, "ts"); write_namespace_decl (out, "split"); + write_namespace_decl (out, "act"); + write_namespace_decl (out, "price"); write_namespace_decl (out, "sx"); - */ + write_namespace_decl (out, "ts"); + write_namespace_decl (out, "slot"); + write_namespace_decl (out, "cust"); + write_namespace_decl (out, "addr"); + fprintf(out, ">\n"); } Index: src/backend/file/sixtp.c =================================================================== RCS file: /home/cvs/cvsroot/gnucash/src/backend/file/sixtp.c,v retrieving revision 1.7 diff -u -r1.7 sixtp.c --- src/backend/file/sixtp.c 24 Dec 2002 02:27:09 -0000 1.7 +++ src/backend/file/sixtp.c 9 Aug 2003 02:59:16 -0000 @@ -832,7 +832,7 @@ return FALSE; } - tag_compare = g_strdup_printf("<%s>", first_tag); + tag_compare = g_strdup_printf("<%s", first_tag); result = (strncmp(cursor, tag_compare, strlen(tag_compare)) == 0); g_free (tag_compare);
_______________________________________________ gnucash-devel mailing list [EMAIL PROTECTED] http://www.gnucash.org/cgi-bin/mailman/listinfo/gnucash-devel