Skip to main content

xml-parser

Parse XML strings into objects or stringify objects into XML format.

Overview

The xml-parser node converts between XML strings and JavaScript objects. Parse incoming XML from APIs, SOAP services, and configuration files into usable objects, or stringify objects back into XML for transmission. Attributes are preserved with @ prefix and text content as #text.

Parse
XML to object
Stringify
Object to XML
@attr
Attribute support
Nested
Deep elements

Properties

Property Type Default Description
action string "parse" "parse" (XML string → object) or "stringify" (object → XML string)

XML to Object Mapping

The parser maps XML structure to JSON objects using these conventions.

Elements

Each XML element becomes an object key with its children as nested objects.

@attributes

XML attributes are stored with @ prefix: @id, @class.

#text

Text content of elements is stored in the #text property.

Example: Parse SOAP API Response

Parse an XML response from a SOAP web service into a usable object.

// xml-parser node configuration
{
  "action": "parse"
}

// Input XML string in msg.payload.data:
// <response status="ok">
//   <temperature unit="celsius">23.5</temperature>
//   <humidity unit="percent">65</humidity>
// </response>

// Output after parsing:
{
  "payload": {
    "data": {
      "@status": "ok",
      "temperature": {
        "@unit": "celsius",
        "#text": "23.5"
      },
      "humidity": {
        "@unit": "percent",
        "#text": "65"
      }
    }
  }
}

// Access values:
// msg.payload.data.temperature["#text"] → "23.5"
// msg.payload.data["@status"] → "ok"

Example: Parse Configuration File

Read and parse an XML configuration file to extract settings.

// xml-parser node configuration
{
  "action": "parse"
}

// Input from file-read node:
// <config>
//   <device id="sensor-01" type="temperature"/>
//   <interval>5000</interval>
//   <threshold>30</threshold>
// </config>

// Output:
{
  "payload": {
    "data": {
      "device": {
        "@id": "sensor-01",
        "@type": "temperature"
      },
      "interval": { "#text": "5000" },
      "threshold": { "#text": "30" }
    }
  }
}

// Flow: [file-read config.xml] → [xml-parser] → [set node]

Example: Generate XML Output

Convert an object to XML for sending to a SOAP service or saving to a file.

// xml-parser node configuration
{
  "action": "stringify"
}

// Input object in msg.payload.data:
{
  "payload": {
    "data": {
      "sensor": "dht22",
      "temperature": 23.5,
      "humidity": 65
    }
  }
}

// Output XML string in msg.payload.data
// Can be sent via HTTP or written to file

// Flow: [function build obj] → [xml-parser stringify] → [http-request]

Common Use Cases

SOAP Web Services

Parse XML responses from legacy SOAP APIs and enterprise services

Configuration Files

Read and write XML config files for device and application settings

RSS / Atom Feeds

Parse XML-based RSS and Atom feeds for content aggregation

Industrial Protocols

Handle XML-based protocols like OPC UA and BACnet/WS

Related Nodes