Skip to content

Commit 7060dd8

Browse files
author
Adrian Hamm
committed
Add fn:xml-to-json()
Add documentation and examples for fn:xml-to-json().
1 parent d9188fd commit 7060dd8

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# fn:xml-to-json() ([specification](https://www.w3.org/TR/xpath-functions-31/#func-xml-to-json"))
2+
handles most valid input according to specification. Notable exceptions follow.
3+
4+
All (un-)escaping is delegated to com.fasterxml.jackson. All output is generated by jackson
5+
and should be proper JSON.
6+
7+
`fn:xml-to-json()` does not replace codepoints in the range `1-31` or `127-159` in any string or map key.
8+
9+
`fn:xml-to-json()` unescapes and reescapes any string and map key marked as being escaped.
10+
It does not do additional special character replacements mentioned in the spec.
11+
It does not do an otherwise verbatim copy.
12+
13+
# Examples
14+
## 1)
15+
```xquery
16+
let $node := <string>&#127;</string>
17+
return fn:xml-to-json($node)
18+
```
19+
does return `""` and not `"\u007F"`.
20+
21+
## 2)
22+
```xquery
23+
let $node := <string escaped="true">\/</string>
24+
return fn:xml-to-json($node)
25+
```
26+
does return `"/"` and not `"\/"`.
27+
28+
##3)
29+
```xquery
30+
let $node := <string escaped="true">&#127;</string>
31+
return fn:xml-to-json($node)
32+
```
33+
does return `""` and not `"\u007F"`.
34+
35+
## 4)
36+
```xquery
37+
let $node := <string escaped="true">""</string>
38+
return fn:xml-to-json($node)
39+
```
40+
does return `""` and not `"\"\""`.
41+

0 commit comments

Comments
 (0)