30 #include "gnc-xml-helper.h" 33 #include "sixtp-utils.h" 34 #include "sixtp-parsers.h" 35 #include "sixtp-utils.h" 36 #include "sixtp-dom-parsers.h" 37 #include "sixtp-dom-generators.h" 40 #include "io-gncxml-gen.h" 43 #include "gnc-address-xml-v2.h" 45 static QofLogModule log_module = GNC_MOD_IO;
47 const gchar* address_version_string =
"2.0.0";
50 #define addr_name_string "addr:name" 51 #define addr_addr1_string "addr:addr1" 52 #define addr_addr2_string "addr:addr2" 53 #define addr_addr3_string "addr:addr3" 54 #define addr_addr4_string "addr:addr4" 55 #define addr_phone_string "addr:phone" 56 #define addr_fax_string "addr:fax" 57 #define addr_email_string "addr:email" 58 #define addr_slots_string "addr:slots" 61 maybe_add_string (xmlNodePtr ptr,
const char* tag,
const char* str)
64 xmlAddChild (ptr, text_to_dom_tree (tag, str));
68 gnc_address_to_dom_tree (
const char* tag,
GncAddress* addr)
72 ret = xmlNewNode (NULL, BAD_CAST tag);
73 xmlSetProp (ret, BAD_CAST
"version", BAD_CAST address_version_string);
75 maybe_add_string (ret, addr_name_string, gncAddressGetName (addr));
77 maybe_add_string (ret, addr_addr1_string, gncAddressGetAddr1 (addr));
78 maybe_add_string (ret, addr_addr2_string, gncAddressGetAddr2 (addr));
79 maybe_add_string (ret, addr_addr3_string, gncAddressGetAddr3 (addr));
80 maybe_add_string (ret, addr_addr4_string, gncAddressGetAddr4 (addr));
82 maybe_add_string (ret, addr_phone_string, gncAddressGetPhone (addr));
83 maybe_add_string (ret, addr_fax_string, gncAddressGetFax (addr));
84 maybe_add_string (ret, addr_email_string, gncAddressGetEmail (addr));
87 xmlAddChild (ret, qof_instance_slots_to_dom_tree (addr_slots_string,
88 QOF_INSTANCE (addr)));
100 set_string (xmlNodePtr node,
GncAddress* addr,
101 void (*func) (
GncAddress* addr,
const char* txt))
103 gchar* txt = dom_tree_to_text (node);
104 g_return_val_if_fail (txt, FALSE);
114 address_name_handler (xmlNodePtr node, gpointer addr_pdata)
116 struct address_pdata* pdata =
static_cast<decltype (pdata)
> (addr_pdata);
118 return set_string (node, pdata->address, gncAddressSetName);
122 address_addr1_handler (xmlNodePtr node, gpointer addr_pdata)
124 struct address_pdata* pdata =
static_cast<decltype (pdata)
> (addr_pdata);
126 return set_string (node, pdata->address, gncAddressSetAddr1);
130 address_addr2_handler (xmlNodePtr node, gpointer addr_pdata)
132 struct address_pdata* pdata =
static_cast<decltype (pdata)
> (addr_pdata);
134 return set_string (node, pdata->address, gncAddressSetAddr2);
138 address_addr3_handler (xmlNodePtr node, gpointer addr_pdata)
140 struct address_pdata* pdata =
static_cast<decltype (pdata)
> (addr_pdata);
142 return set_string (node, pdata->address, gncAddressSetAddr3);
146 address_addr4_handler (xmlNodePtr node, gpointer addr_pdata)
148 struct address_pdata* pdata =
static_cast<decltype (pdata)
> (addr_pdata);
150 return set_string (node, pdata->address, gncAddressSetAddr4);
154 address_phone_handler (xmlNodePtr node, gpointer addr_pdata)
156 struct address_pdata* pdata =
static_cast<decltype (pdata)
> (addr_pdata);
158 return set_string (node, pdata->address, gncAddressSetPhone);
162 address_fax_handler (xmlNodePtr node, gpointer addr_pdata)
164 struct address_pdata* pdata =
static_cast<decltype (pdata)
> (addr_pdata);
166 return set_string (node, pdata->address, gncAddressSetFax);
170 address_email_handler (xmlNodePtr node, gpointer addr_pdata)
172 struct address_pdata* pdata =
static_cast<decltype (pdata)
> (addr_pdata);
174 return set_string (node, pdata->address, gncAddressSetEmail);
178 address_slots_handler (xmlNodePtr node, gpointer addr_pdata)
180 struct address_pdata* pdata =
static_cast<decltype (pdata)
> (addr_pdata);
181 return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->address));
186 { addr_name_string, address_name_handler, 0, 0 },
187 { addr_addr1_string, address_addr1_handler, 0, 0 },
188 { addr_addr2_string, address_addr2_handler, 0, 0 },
189 { addr_addr3_string, address_addr3_handler, 0, 0 },
190 { addr_addr4_string, address_addr4_handler, 0, 0 },
191 { addr_phone_string, address_phone_handler, 0, 0 },
192 { addr_fax_string, address_fax_handler, 0, 0 },
193 { addr_email_string, address_email_handler, 0, 0 },
194 { addr_slots_string, address_slots_handler, 0, 0 },
199 gnc_dom_tree_to_address (xmlNodePtr node,
GncAddress* address)
204 addr_pdata.address = address;
206 successful = dom_tree_generic_parse (node, address_handlers_v2,
211 PERR (
"failed to parse address tree");
218 address_ns (FILE* out)
220 g_return_val_if_fail (out, FALSE);
221 return gnc_xml2_write_namespace_decl (out,
"addr");
225 gnc_address_xml_initialize (
void)
227 static GncXmlDataType_t be_data =
229 GNC_FILE_BACKEND_VERS,
239 gnc_xml_register_backend (be_data);
#define PERR(format, args...)
Log a serious error.
api for GnuCash version 2 XML-based file format