Action that parses XML data and extracts content using XPath expressions Supports namespaces, various return types, and multiple input sources

Example

// Parse XML and extract with XPath
await runAction({
ActionName: 'XML Parser',
Params: [{
Name: 'XMLData',
Value: '<users><user id="1"><name>John</name></user><user id="2"><name>Jane</name></user></users>'
}, {
Name: 'XPathExpression',
Value: '//user[@id="1"]/name/text()'
}]
});

// Parse XML with namespaces
await runAction({
ActionName: 'XML Parser',
Params: [{
Name: 'XMLData',
Value: '<ns:root xmlns:ns="http://example.com"><ns:value>Test</ns:value></ns:root>'
}, {
Name: 'XPathExpression',
Value: '//ns:value/text()'
}, {
Name: 'NamespaceMap',
Value: { ns: 'http://example.com' }
}]
});

// Convert entire XML to JSON
await runAction({
ActionName: 'XML Parser',
Params: [{
Name: 'XMLData',
Value: '<root><item>Value 1</item><item>Value 2</item></root>'
}]
});

Hierarchy

  • BaseFileHandlerAction
    • XMLParserAction

Constructors

Methods

  • Parses XML and extracts data using XPath expressions

    Parameters

    • params: RunActionParams<any>

      The action parameters containing:

      • XMLData: String containing XML data (direct input)
      • FileID: UUID of MJ Storage file (alternative)
      • FileURL: URL of XML file (alternative)
      • XPathExpression: XPath query to extract data (optional - if not provided, converts entire XML to JSON)
      • NamespaceMap: Object mapping namespace prefixes to URIs
      • ReturnType: "string" | "number" | "boolean" | "node" | "nodes" | "json" (default: "string")
      • PreserveAttributes: Boolean - include attributes in JSON conversion (default: true)
      • ExplicitArray: Boolean - always put child nodes in array (default: false)
      • IgnoreAttributes: Boolean - ignore attributes in conversion (default: false)

    Returns Promise<ActionResultSimple>

    Extracted data based on XPath or full JSON conversion

  • Executes the action with the provided parameters.

    Parameters

    • params: RunActionParams<any>

      The action execution parameters including context

    Returns Promise<ActionResultSimple>

    Promise resolving to the action result

  • Extract data using XPath

    Parameters

    • xmlString: string
    • xpathExpression: string
    • namespaceMap: Record<string, string>
    • returnType: string

    Returns Promise<any>

  • Get file content from various sources based on parameters Priority: FileID > FileURL > Data parameter

    Parameters

    • params: RunActionParams<any>

      Action parameters

    • dataParamName: string

      Name of the parameter containing direct data

    • fileParamName: string = 'FileID'

      Name of the parameter containing file ID (default: 'FileID')

    • urlParamName: string = 'FileURL'

      Name of the parameter containing file URL (default: 'FileURL')

    Returns Promise<{
        content: string | Buffer;
        fileName?: string;
        mimeType?: string;
        source: "url" | "storage" | "direct";
    }>

    Object with content and metadata