[GNC] Python xml library that supports XMLNS for GNC

John Ralls jralls at ceridwen.us
Sun Oct 27 16:30:22 EDT 2024


> On Oct 27, 2024, at 12:55, AC <gnucash at acarver.net> wrote:
> 
> I need to do a search-and-replace to change one of the sides of a split from one account to another but only for specific transactions that meet a criteria. I was trying xml.etree but it did not write out the namespace correctly so is there another XML library that supports XPath searching as well as handles GNC's namespace design such that the written file is correct?
> 
> 
> In this case I'm trying to change the account GUID of one half of the split to a different GUID but only for transactions that match a very specific description text and have the old GUID as one of the two split accounts. I already know both the old and new GUIDs but this isn't a simple search and replace all the GUIDs that match because the account with the old GUID has transactions that should stay, hence doing XPath searching to filter down on the specific XML tree elements that match the criteria.
> 
> When I wrote out the XML using xml.etree it wrote namespaces like 'xmlns:ns7', 'xmlns:ns8', etc. even though I had already registered the namespace at the beginning using what was originally in the GNC XML file. It did replace some of the namespace data, but not all of it leaving the 'ns*' names.
> ______________________________________________


First try loading your modified file with the serialized namespace abbreviations into GnuCash, it might just work. The actual namespaces are the URIs at the top of the file and the abbreviations are local to the file so as long as there’s a correct xmlins declaration for “ns7” and friends it should load correctly.

If it doesn’t, GnuCash uses Gnome libxml2 and it includes python bindings. Look for packages with names like `libxml2-python` in your package manager.

Regards,
John Rals



More information about the gnucash-user mailing list