Dear Wray,
I tried to come up with a sketch of what–I think–might help you:
Basically it boils down to:
1. Fetch the JSON
2. Convert that JSON to an XQuery item
3. Iterate over each array entry and explicitly construct the XML representation you want
So in a nutshell, in XQuery 3.1, something like the following:
=> parse-json() (: Convert to XQuery item representation :)
=> array:for-each(function($map){ (: For each entry in that array, do :)
element item { (: Construct an XML element named item :)
$map => map:keys()
=> for-each(function($key){ (: For each key in the map, do: :)
element { $key } { (: Return an element named $key :)
$map($key) (: …and the value of $map($key) :)
}
})
}
})
=> array:flatten() (: Converts the array to a sequence :)
I assume you are using BaseX, so maybe the json:parse() function might be another option, that is based on our own implementation and will create an XML representation right away:
As I can only guess what your XQuery code actually looks like I hope this comes somewhat close to what you want.
Hope this helps ;-)
Best from Konstanz
Michael
I want to load it into a database in a different XML format where I can use gml:Point in place of longitude and latitude as separate elements. However my for loop does not emit individual XML elements for each json object in the loaded array.