$$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,
"cdata_tag_name": "$content",
"convert_nil_to_null": false,
"force_list": [ /* tag names */ ]
}
"$$xmlparse([keep_strings],[convert_nil_to_null]):{input}"
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 (String)
Definition
Output
<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": "$"
}
{
"root": {
"hello": {
"hi": { "test": "X" },
"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="2">
<hi>true</hi>
</hello>
</root>
{
"$$xmlparse": "$"
}
{
"root": {
"hello": {
"hi": true,
"to": 2
}
}
}
<root>
<hello to="2">
<hi>true</hi>
</hello>
</root>
{
"$$xmlparse": "$",
"keep_strings": true
}
{
"root": {
"hello": {
"hi": "true",
"to": "2"
}
}
}
<root></root>
"$$xmlparse:$"
{ "root": "" }
<root>
<hello to="world">
<hi />
<hi />
</hello>
</root>
"$$xmlparse:$"
{
"root": {
"hello": {
"hi": [ "", "" ],
"to": "world"
}
}
}
<root>
<hello to="2">
<hi>true</hi>
</hello>
</root>
"$$xmlparse:$"
{
"root": {
"hello": {
"hi": true,
"to": 2
}
}
}
<root>
<hello to="2">
<hi>true</hi>
</hello>
</root>
"$$xmlparse(true):$"
{
"root": {
"hello": {
"hi": "true",
"to": "2"
}
}
}