looking to #programmatically #transform data from a proprietary #XML format into an open #JSON format, #geojson to be specific.
any suggestions on good ways to proceed using #python?
Emphasis should be placed on the *transform* step (e.g., I can't simply convert the XML to JSON, I need to modify fields/values).
@davidshq I'd use xslt3 for that. There is a learning curve, but it is the right tool for this kind of job. Saxon can be called from Python if Python is what you need to use on the top level https://www.saxonica.com/saxon-c/doc11/html/saxonc.html #xml
@hanshuebner @davidshq Oh yes. XSLT is an underappreciated gem.
@davidshq You could parse your custom XML data into either shapely objects https://shapely.readthedocs.io/en/stable/ or a SpatiaLite DB (extension for SQLite) https://www.gaia-gis.it/fossil/libspatialite/index as an intermediate representation.
Having done your transformations, it is easy to dump from either Shapely objects or a SpatiaLite DB to GeoJSON.
Also lots of people suggesting pandas. If you go that route, you could look into https://geopandas.org/en/stable/ but I have not used this myself.
@chris thanks! I found an example of someone using shapely to convert from xml to qupath, I'll take a look at shapely
@davidshq I was looking for something similar earlier today for a one-off and discovered a package called "yq" that turns YAML into JSON and passes it into jq.
The yq package includes another one called "xq" which takes in XML and emits JSON.
And since the whole thing runs through jq, you have the ability to query and/or alter the JSON output as needed.
Third times the charm, right? Here's the *CORRECT* link
@davidshq Related to that, xq is based on something called xmltodict
@ThatBlairGuy Cool, I'll take a look. xmltodict is one module I'd been looking at!