Possible approaches to mapping XML into CUE Values #3747
Unanswered
lorrrrrrrenzo
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summarizing and continuing public and private conversations concerning the addition of
encoding/xml
to CUE and the need to arrive at an acceptable XML->CUE mapping.Approach 1
My naive approach to this placed attributes of an XML node into an
attrs
array, with each child node added to achildren
list. With this approach I was able to translate XML to CUE and back, albeit with some deviations that seem straightforward to address. The issue here is that the resulting CUE seems 'unergonomic' and out of line with how other CUE I've seen is structured. One example of this is how CUE paths turn into an inscrutable chain of repetitive array access clauses (e.g.,encoded.children[2].children.[1].children[0].attrs.identifier
). This strikes me as undesirable, especially when thinking about this CUE would need to interact with other CUE and writing abstract definitions to constrain XML formats.Example XML
Example CUE
Approach 2
Matthew turned me on to BadgerFish (homepage, Google Cloud documentation), which is one accepted approach of translating XML into JSON. One benefit is that the CUE paths are far more sensible (e.g.,
A.alice.bob.$
) and the resulting CUE is more compact and much easier to write constraints against. I have not deeply checked if the XML can be stably* recreated from this encoding, but my sense from looking at it is that it should not be a problem.(NB: By "stable recreation" here I pointedly exclude the goal of recreating the original XML input, instead preferring the goal of stability of regeneration once the XML document has been marshalled into CUE. In other projects I've seen requests for libraries to support the exact recreation of the original XML document after a round-trip, but that seems to add a lot of difficulty without much benefit.)
Example XML (same as above)
Example CUE
I'm not convinced that this is a final answer, but I think it's a useful starting point for a technical discussion.
Outstanding Questions
Beta Was this translation helpful? Give feedback.
All reactions