GNOME Bugzilla – Bug 680887
[contribution] RELAX NG schema for 2.4.11 XML file format
Last modified: 2018-06-29 23:09:54 UTC
Created attachment 219954 [details] [review] Updated RELAX NG schema for 2.4.11 Hi, while I know GnuCash cannot commit to a constant XML schema, it is sometimes useful to be able to validate the files produced by a given version (I for one have such a need for tax reporting purposes). In these cases, the non-normative RELAX NG schema at 'src/doc/xml/gnucash-v2.rnc' is handy. However, it has not been updated since 2006, and, while the GnuCash format is in practice quite stable, most current files no more validate. Here is an updated schema to match the format produced by version 2.4.11. I based my work directly on the source code (in directories 'src/backend/xml' and 'src/engine'). In order to make future updating easier, I wrote down the appropriate reference for each part of the schema in comments. This schema has been tested with my own GnuCash files, the ones in directory 'src/backend/xml/test/test-files/xml2' and a few others from the web. They all validate. However, these files mostly use the base features (commodities, accounts and transactions), so that less common features stay untested. Cheers, Baptiste
Thanks for the contribution. I'm categorising this as XML Backend.
Comment on attachment 219954 [details] [review] Updated RELAX NG schema for 2.4.11 Thank you for your contribution. I have committed it in the development branch already and intend to commit it in the stable series as well, but there are currently some network issues. Just out of curiosity: which tool do you use to test the validation of your gnucash files ? I'd like to try this as well with mine (I am using the business features a lot, so my data files can be a good test case for the schema as well).
To answer Geert's tool question: until now, I used a 2-step process: 1) convert the schema to XML syntax (.rng) using trang [1]. 2) validate with xmllint from libxml2 (any other XML validator will do, for example, the python-lxml bindings work too). However, I just found out I can do it in one step with jing (same homepage as trang). Also, I won't miss xmllint's error reporting, which is rather confusing. So the old way was: trang gnucash-v2.rnc gnucash-v2.rng xmllint --relaxng gnucash-v2.rng --noout test.gnucash And the new way (less tested, but probably better) would be: jing -c gnucash-v2.rnc test.gnucash echo $? (just to check, jing is silent on success) If you have any questions with validation errors with your files, just ask me. Most probably you will find some cases where the schema is too constrained, as I've tried to be quite strict. [1] http://code.google.com/p/jing-trang/
Thanks for the information. jing is packaged for Fedora, so I could easily install and test it. The schema didn't give any errors on a business file I use with GnuCash 2.4.11. So nice work ! The development series introduces a new element in the schema, which is not in your rng file yet: test.xac:258073:18: error: element "invoice:slots" not allowed anywhere; expected the element end-tag or element "invoice:billto" or "invoice:charge-amt" If you want to fix this, I will gladly add an updated rng file for the development series. By the way, I have added a small note in the wiki to document the way to validate a gnucash xml file based on your information: http://wiki.gnucash.org/wiki/GnuCash_XML_format#Validation
Created attachment 221810 [details] schema for the development version
Created attachment 221811 [details] schema for the stable version
Hello, indeed, the format has changed. The element type "invoice:slots", which previously had code only for parsing, but not for writing, is now exported. As a side note: similar unused "slots" element types (with code for parsing, probably for forward-compatibility) exist for other business objects. So similar format changes could happen in the future. I have attached an updated schema for the development trunk (as of revision 22330). While doing this, I got aware of a small bug in my 2.4.11 schema, so I updated it too. Cheers, Baptiste
Sorry for the long silence. I have just committed your updated rng schemas to the proper branches. I have also added a README file in the xml directory to explain how the relax ng schema can be used, based on your explanation in comment 3. This will only appear in the next stable release though. Thanks a lot for your contributions !
Reassign version to 2.4.x so that individual 2.4 versions can be retired.
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=680887. Please update any external references or bookmarks.