$$xmlparse
Parses an XML and converts it to an object
- Elements with text and attributes will be converted to objects with a
$content
field for the text
Usage​
{
"$$xmlparse": /* XML string */,
"keep_strings": false /* boolean */,
"cdata_tag_name": "$content" /* string */,
"convert_nil_to_null": false /* boolean */,
"force_list": [] /* string[] */
}
"$$xmlparse([keep_strings],[cdata_tag_name],[convert_nil_to_null],[force_list]):{input}"
note
Concrete values in the usage example are default values.
Returns​
object
Arguments​
Argument | Type | Values | Required / Default Value | Description |
---|---|---|---|---|
Primary | string | Yes | XML string | |
keep_strings | boolean | false /true | false | Do not try to detect primitive types (e.g. numbers, boolean, etc) |
cdata_tag_name | string | "$content" | A key for the CDATA section | |
convert_nil_to_null | boolean | false /true | false | If values with attribute xsi:nil="true" will be converted to null |
force_list | string[] | [] | Tag names that will always be parsed as arrays |
Examples​
Input
Definition
Output
<root></root>
"$$xmlparse:$"
{
"root": ""
}
<root><hello to="world"><hi /><hi /></hello></root>
"$$xmlparse:$"
{
"root": {
"hello": {
"hi": [
"",
""
],
"to": "world"
}
}
}
<root></root>
{
"$$xmlparse": "$"
}
{
"root": ""
}
<root><hello to="world"><hi /><hi /></hello></root>
{
"$$xmlparse": "$"
}
{
"root": {
"hello": {
"hi": [
"",
""
],
"to": "world"
}
}
}
<root><hello to="world"><hi><test>X</test></hi></hello></root>
{
"$$xmlparse": "$",
"force_list": [
"hi"
]
}
{
"root": {
"hello": {
"hi": [
{
"test": "X"
}
],
"to": "world"
}
}
}
<root><hello to="world"><hi /><hi /></hello></root>
{
"$$xmlparse": "$",
"force_list": [
"hi"
]
}
{
"root": {
"hello": {
"hi": [],
"to": "world"
}
}
}
<root><hello to="2"><hi>true</hi></hello></root>
{
"$$xmlparse": "$",
"keep_strings": true
}
{
"root": {
"hello": {
"hi": "true",
"to": "2"
}
}
}
<root><hello to="2"><hi>true</hi></hello></root>
{
"$$xmlparse": "$"
}
{
"root": {
"hello": {
"hi": true,
"to": 2
}
}
}