$$xmlparse
Parses an XML and converts it to an object
- Elements with text and attributes will be converted to objects with a
#textfield for the text
Usage​
{
"$$xmlparse": /* XML string */,
"keep_strings": false /* boolean */,
"cdata_prop_name": "#text" /* string */,
"attr_prefix": "@" /* string */,
"array_tags": [] /* string[] */
}
"$$xmlparse([keep_strings],[cdata_prop_name],[attr_prefix],[array_tags]):{input}"
note
Concrete values in the usage example are default values.
Returns​
object
Arguments​
| Argument | Type | Values | Required / Default Value | Description |
|---|---|---|---|---|
| Input | string | Yes | XML string | |
keep_strings | boolean | false/true | false | Do not try to detect primitive types (e.g. numbers, boolean, etc) |
attr_prefix | string | "@" | Prefix for properties extracted from XML attributes | |
cdata_prop_name | string | "#text" | A key for the text/CDATA section (when needed) | |
array_tags | 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": "$"
}
{
"root": {
"hello": {
"hi": {
"test": "X"
},
"@to": "world"
}
}
}
<root><hello to="world"><hi><test>X</test></hi></hello></root>
{
"$$xmlparse": "$",
"array_tags": [
"hi"
]
}
{
"root": {
"hello": {
"hi": [
{
"test": "X"
}
],
"@to": "world"
}
}
}
<root><hello to="world"><hi /><hi /></hello></root>
{
"$$xmlparse": "$",
"array_tags": [
"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
}
}
}