Skip to main content

$$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​

ArgumentTypeValuesRequired / Default ValueDescription
PrimarystringYesXML string
keep_stringsbooleanfalse/truefalseDo not try to detect primitive types (e.g. numbers, boolean, etc)
cdata_tag_namestring"$content"A key for the CDATA section
convert_nil_to_nullbooleanfalse/truefalseIf values with attribute xsi:nil="true" will be converted to null
force_liststring[][]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"
}
}
}