diff --git a/src/backend/file/io-gncxml-v2.c b/src/backend/file/io-gncxml-v2.c index a4ca1f0286..3fdb5b027d 100644 --- a/src/backend/file/io-gncxml-v2.c +++ b/src/backend/file/io-gncxml-v2.c @@ -763,13 +763,37 @@ write_schedXactions( FILE *out, GNCBook *book ) } while ( (schedXactions = schedXactions->next) ); } +static void +write_namespace_decl (FILE *out, const char *namespace) +{ + g_return_if_fail (namespace); + fprintf(out, " xmlns:%s=\"\"", namespace); +} + +static void +write_v2_header (FILE *out) +{ + fprintf(out, "\n"); + fprintf(out, "<" GNC_V2_STRING); + /* + write_namespace_decl (out, "cd"); + 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, "sx"); + */ + fprintf(out, ">\n"); +} + gboolean gnc_book_write_to_xml_filehandle_v2(GNCBook *book, FILE *out) { if (!out) return FALSE; - fprintf(out, "\n"); - fprintf(out, "<" GNC_V2_STRING ">\n"); + write_v2_header (out); write_counts(out, "commodity", @@ -800,6 +824,30 @@ gnc_book_write_to_xml_filehandle_v2(GNCBook *book, FILE *out) return TRUE; } +gboolean +gnc_book_write_accounts_to_xml_filehandle_v2(GNCBook *book, FILE *out) +{ + if (!out) return FALSE; + + write_v2_header (out); + + write_counts(out, + "commodity", + gnc_commodity_table_get_size( + gnc_book_get_commodity_table(book)), + "account", + xaccGroupGetNumSubAccounts(gnc_book_get_group(book)), + NULL); + + write_commodities(out, book); + + write_accounts(out, book); + + fprintf(out, "\n\n"); + + return TRUE; +} + gboolean gnc_book_write_to_xml_file_v2(GNCBook *book, const char *filename) { diff --git a/src/backend/file/io-gncxml-v2.h b/src/backend/file/io-gncxml-v2.h index e675dc65c1..057af24ad9 100644 --- a/src/backend/file/io-gncxml-v2.h +++ b/src/backend/file/io-gncxml-v2.h @@ -83,10 +83,14 @@ gboolean gnc_session_load_from_xml_file_v2( GNCSession *session, void (*countcallback)(const char *type, load_counter count)); -/* write all account info to a file */ +/* write all book info to a file */ gboolean gnc_book_write_to_xml_filehandle_v2(GNCBook *book, FILE *fh); gboolean gnc_book_write_to_xml_file_v2(GNCBook *book, const char *filename); +/* write just the commodities and accounts to a file */ +gboolean gnc_book_write_accounts_to_xml_filehandle_v2(GNCBook *book, + FILE *out); + /* The is_gncxml_file() routine checks to see if the first few * chars of the file look like gnc-xml data. */ diff --git a/src/gnome/window-main.c b/src/gnome/window-main.c index f9a0f73e3b..a111003a2a 100644 --- a/src/gnome/window-main.c +++ b/src/gnome/window-main.c @@ -55,7 +55,7 @@ #include "gnc-menu-extensions.h" #include "gnc-ui.h" #include "gnucash.h" -#include "io-utils.h" +#include "io-gncxml-v2.h" #include "mainwindow-account-tree.h" #include "option-util.h" #include "top-level.h" @@ -394,33 +394,11 @@ gnc_main_window_file_export_cb(GtkWidget * widget, gpointer data) return; } - ok = FALSE; + ok = gnc_book_write_accounts_to_xml_filehandle_v2 (gnc_get_current_book (), + file); - do - { - rc = fputs ("\n", file); - if (rc == EOF) - break; - - rc = fputs ("\n", file); - if (rc == EOF) - break; - - write_commodities (file, gnc_get_current_book ()); - write_accounts (file, gnc_get_current_book ()); - - rc = fputs ("<\\gnc-v2>\n", file); - if (rc == EOF) - break; - - write_emacs_trailer (file); - - rc = fclose (file); - if (rc != 0) - break; - - ok = TRUE; - } while (FALSE); + if (fclose (file) != 0) + ok = FALSE; if (!ok) {