-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[xq31] Why don't json-to-xml() and xml-to-json() process JSON as item() ? #34
Comments
It's always hard to give a definitive answer to "why" questions, but I suspect the answer can be found in the development timeline.
The two functions were arlready defined in a 2014 draft of XSLT 3.0
https://www.w3.org/TR/2014/WD-xslt-30-20141002/
at which time there was no support in the XDM data model for arrays, and in fact the WG had become very bogged down trying to find an acceptable way to represent arrays in the data model. Direct conversion between the lexical representation of JSON and XML, bypassing any need for maps and arrays, was a solution to this problem. In fact right until the final release of XSLT 3.0 there was a reluctance among some members of the XSL Working Group to make the specification dependent on XPath 3.1, which is where arrays were first supported in the data model.
Michael Kay
Saxonica
… On 10 Dec 2021, at 13:50, Reino Wijnsma ***@***.***> wrote:
https://www.w3.org/TR/xpath-functions-31/#func-json-to-xml <https://www.w3.org/TR/xpath-functions-31/#func-json-to-xml>:
fn:json-to-xml($json-text as xs:string?) as document-node()?
[...]
json-to-xml('{"x": 1, "y": [3,4,5]}')
Why has it been decided to have this function accept the JSON as xs:string?
Intuitively, without reading the documentation, I would've entered json-to-xml(map{"x":1,"y":[3,4,5]}). It's in the name after all.
https://www.w3.org/TR/xpath-functions-31/#func-xml-to-json <https://www.w3.org/TR/xpath-functions-31/#func-xml-to-json>:
fn:xml-to-json($input as node()?) as xs:string?
[...]
The input <array xmlns="http://www.w3.org/2005/xpath-functions"><number>1</number><string>is</string><boolean>1</boolean></array> produces the result [1,"is",true].
Why has it been decided to have this function put out the JSON as xs:string?
Intuitively, without reading the documentation, I would've expected xml-to-json(<array xmlns="http://www.w3.org/2005/xpath-functions"><number>1</number><string>is</string><boolean>1</boolean></array>) to put out [1,"is",true] as item() (like parse-json()). It's in the name after all.
Why is XML processed as (document-)node(), but JSON not as item()? This...
fn:json-to-xml($json as item()?) as document-node()?
fn:xml-to-json($input as node()?) as item()?
...would've been much more obvious to me.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#34>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AASIQIUGVGYUTM4X5J3NR73UQIASXANCNFSM5JZF5CJA>.
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Thanks for the clarification. Can I then turn this into a request for XPath/XQuery 4.0? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.w3.org/TR/xpath-functions-31/#func-json-to-xml:
Why has it been decided to have this function accept the JSON as
xs:string
?Intuitively, without reading the documentation, I would've entered
json-to-xml(map{"x":1,"y":[3,4,5]})
. It's in the name after all.https://www.w3.org/TR/xpath-functions-31/#func-xml-to-json:
Why has it been decided to have this function put out the JSON as
xs:string
?Intuitively, without reading the documentation, I would've expected
xml-to-json(<array xmlns="http://www.w3.org/2005/xpath-functions"><number>1</number><string>is</string><boolean>1</boolean></array>)
to put out[1,"is",true]
asitem()
(likeparse-json()
). It's in the name after all.Why is XML processed as
(document-)node()
, but JSON not asitem()
? This......would've been much more obvious to me.
The text was updated successfully, but these errors were encountered: