Skip to content

Commit 614f19a

Browse files
authored
Merge pull request #37 from agh2342/feature/xml-to-json
Add fn:xml-to-json()
2 parents d9188fd + 66d6980 commit 614f19a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 output is generated by the `jackson` library and should be proper JSON. All (un-) escaping is delegated to `com.fasterxml.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 `"\"\""`.

0 commit comments

Comments
 (0)