Exemple #1
0
xmlNodePtr
gnc_book_dom_tree_create(QofBook *book)
{
    xmlNodePtr ret;
    G_GNUC_UNUSED gboolean allow_incompat = TRUE;

    ret = xmlNewNode(NULL, BAD_CAST gnc_book_string);
    xmlSetProp(ret, BAD_CAST "version", BAD_CAST gnc_v2_book_version_string);

    xmlAddChild(ret, guid_to_dom_tree(book_id_string,
                                      qof_book_get_guid(book)));

    if (qof_instance_get_slots (QOF_INSTANCE (book)))
    {
        xmlNodePtr kvpnode = kvp_frame_to_dom_tree(book_slots_string,
                             qof_instance_get_slots (QOF_INSTANCE (book)));
        if (kvpnode)
            xmlAddChild(ret, kvpnode);
    }

#ifdef IMPLEMENT_BOOK_DOM_TREES_LATER
    /* theoretically, we should be adding all the below to the book
     * but in fact, there's enough brain damage in the code already
     * that we are only going to hand-edit the file at a higher layer.
     * And that's OK, since its probably a performance boost anyway.
     */
    xmlAddChild(ret, gnc_commodity_dom_tree_create(
                    gnc_commodity_table_get_table(book)));
    xmlAddChild(ret, gnc_pricedb_dom_tree_create(gnc_pricedb_get_db(book)));
    if (allow_incompat)
    {
        accnode = gnc_account_dom_tree_create(account, FALSE);
        xmlAddChild (ret, rootAccNode);
    }
    append_account_tree (ret, gnc_book_get_root(book));

    xaccAccountTreeForEachTransaction (gnc_book_get_root_account(book),
                                       traverse_txns, ret);

    /* xxx FIXME hack alert how are we going to handle
     *  gnc_book_get_template_group handled ???   */
    xmlAddChild(ret, gnc_schedXaction_dom_tree_create(
                    gnc_book_get_schedxactions(book)));

#endif

    return ret;
}
Exemple #2
0
static void
append_account_tree (xmlNodePtr parent,
                     Account *account,
                     gboolean allow_incompat)
{
    GList *children, *node;

    children = gnc_account_get_children(account);
    children = g_list_sort(children, qof_instance_guid_compare);
    for (node = children; node; node = node->next)
    {
        xmlNodePtr accnode;
        Account *account;

        account = node->data;
        accnode = gnc_account_dom_tree_create(account, FALSE, allow_incompat);
        xmlAddChild (parent, accnode);
        append_account_tree(accnode, account);
    }
    g_list_free(children);
}
static void
test_account (int i, Account* test_act)
{
    xmlNodePtr test_node;
    gchar* filename1;
    gchar* compare_msg;
    int fd;

    test_node = gnc_account_dom_tree_create (test_act, FALSE, TRUE);

    if (!test_node)
    {
        failure_args ("account_xml", __FILE__, __LINE__,
                      "gnc_account_dom_tree_create returned NULL");
        return;
    }

    if ((compare_msg = node_and_account_equal (test_node, test_act)) != NULL)
    {
        failure_args ("account_xml", __FILE__, __LINE__,
                      "node and account were not equal: %s", compare_msg);
        xmlElemDump (stdout, NULL, test_node);
        fprintf (stdout, "\n");
        xmlFreeNode (test_node);
        g_free (compare_msg);
        return;
    }
    else
    {
        success ("account_xml");
    }

    filename1 = g_strdup_printf ("test_file_XXXXXX");

    fd = g_mkstemp (filename1);

    write_dom_node_to_file (test_node, fd);

    close (fd);

    {
        sixtp* parser;
        act_data data;

        data.act = test_act;
        data.value = i;

        parser = gnc_account_sixtp_parser_create ();

        if (!gnc_xml_parse_file (parser, filename1, test_add_account,
                                 &data, sixbook))
        {
            failure_args ("gnc_xml_parse_file returned FALSE",
                          __FILE__, __LINE__, "%d", i);
        }

        /* no handling of circular data structures.  We'll do that later */
        /* sixtp_destroy(parser); */
    }


    g_unlink (filename1);
    g_free (filename1);
    xmlFreeNode (test_node);
}