GNOME Bugzilla – Bug 490491
Add support for xsd to xml translation
Last modified: 2021-07-05 13:25:16 UTC
I'm submitting code to provide functionality for generating a valid xml instance document from an XML schema definition. Although the implementation touches the existing libxml code in only a couple of places, because it uses the schemas internals it sits best within libxml itself. The code as submitted implements a subset of XML schemas (enough for what I was working on) but hopefully provides a functional prototype if nothing else.
Created attachment 97913 [details] patch implementing the functionality described Unpack in libxml2 source directory. Includes C source and header files, plus a diff (xsdtrans.diff) to apply with patch. The patch was generated against 2.6.28 and applies cleanly against 2.6.29.
I looked quickly at it, but I get really worried about the maintainability. XSD is already horribly complex in practice and a pain to maintain, I don't see myself adding extra XSD related code to my list. So I'm a bit reluctant honnestly, and it's unclear how useful that would be, Daniel
Up to you, of course. I've seen you comment previously that you weren't keen on the whole XSD thing, and having delved into it I understand your reticence. As to usefulness, I needed it at work, saw a couple of requests for same in the mail archive and have seen a few requests on the list since. The trouble is you have xmlbeans to do this in java and similar tools exist for C++ and other languages, but there is nothing for pure C. In my opinion, this implementation is even better than xmlbeans, which allows only compile-time binding of the schema to your data. Mine is done at runtime via callbacks so you can dynamically handle changes in schema or data to some extent. I couldn't see a way to implement it without accessing the internals, hence I submitted it as a patch to libxml2 rather than have it as a standalone contrib, but maybe someone will find the patches useful, even if they aren't applied to the core library.
Yeah, I understand your point of view. Maybe this should go into some contrib section or something. Clearly it would be a shame to not share the code, but on the other hand I don't feel like providing support for it, especially as a public API ... Daniel
Created attachment 215687 [details] Example code for using schema translation For completeness, here is example code I made for someone showing how to use the schema translator API.
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/libxml2/-/issues/ Thank you for your understanding and your help.