I'm working on a simple database. For me it's the first time that I use gnucash and I must use it. When I save my database I expect a file in .xml or sqlite format but after clicking "Save As" in my save folder I see only a file in .gnucash format and .log files but not in xml or sqlite. I must manage these files in Java IDE. Is there a solution to this problem or is it possible manage directly .gnucash file format directly in Java?
1 Answers
FROM: http://wiki.gnucash.org/wiki/File
How can I edit the file?
The file itself is XML data but in compressed form (compressed by the program gzip).
This is switched on or off according to the preference setting in Edit->Preferences->General where you can set or unset the checkmark at File compression. By default it is activated.
In order to have a look at your data by a text editor, you need to open a terminal window (console window) and enter the following commands:
mv foobar foobar-copy.gz
gunzip foobar-copy.gz
where you need to replace "foobar" by your actual file name, of course. After > these two commands have been entered, you can open the resulting file "foobar-copy" > in a text editor.
When you intend to make some manual changes, as we have done, make sure to have a backup of your original file somewhere in case you get something wrong. In this case, the original file, "foobar" is intact.
Once you have edited and saved the file, you don't have to gzip it yourself; GnuCash will do this upon the next save.
In short, the xml file, (And I'm speculating the sqlite file) is compressed and you need to decompress them before you can edit them. Or you can tell GNUCash to skip the compression.
-
Ok, I have solved my problem simply open gnucash file with notepad or text editor. But when I open my gnucash file save as xml (for example) I don't find values that I have inserted. These values must be managed in Java – Nico Jul 25 '16 at 08:25
-
I couldn't help you on that, I haven't checked what it looks like. Did you try to find parts of the transaction. Such as if you put something in [Wallet] with the description [Walmart] at the price of 24.50; Not having looked at the xml myself maybe it's something like
24 50 Maybe search for a known check number and look at the structure form there. – Mallow Jul 25 '16 at 13:18 -
Ok, I've found values which I've inserted in xml file. The only strange thing is value is not expressed as integer but as number divided to 100. For example if I insert 900,00$, the xml file returns 90000/100. Is there a parameter in Preferences that I can modify to see value inserted in a correct way? – Nico Jul 25 '16 at 14:33
-
I have no idea if you can modify this in the preferences or not. However the /100 seems to indicate that instead of storing the currency value as a float, they store it as an integer and divide it by 100. So that say 19.99 is 1999/100. So you could just parse that logic in your java. You will probably want to read http://wiki.gnucash.org/wiki/GnuCash_XML_format and https://github.com/sdementen/piecash The latter being a python parser for gnucash, It might have hints on what they did, or might be what you are looking for just in python instead of java. – Mallow Jul 25 '16 at 15:11