Trouble converting XML

Hello everyone,

In my flow I have a watch node watching a folder that receives multiple XML files. I then use a switch node to traffic the flow by filename and then would like to parse the XML to a JS object. However, I receive "Error: Invalid character in name".
I tried looking it up and saw that someone once said that it occures when keys begins with numbers in the xml file, however this is not the case in my situtation.

What am I doing wrong?

This is my flow:

[
    {
        "id": "c672c0fdbe993a93",
        "type": "tab",
        "label": "C5 Dashboard",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "1c2140d6f2296c41",
        "type": "watch",
        "z": "c672c0fdbe993a93",
        "name": "",
        "files": "C:\\c5_dashboard\\Dashboard",
        "recursive": "",
        "x": 200,
        "y": 200,
        "wires": [
            [
                "a7703a966d5a9e1c",
                "dc3818e5.3c2fa8"
            ]
        ]
    },
    {
        "id": "34ab96b62d500e37",
        "type": "switch",
        "z": "c672c0fdbe993a93",
        "name": "",
        "property": "filename",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "KeepAliveReport.xml",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "OpenDepositReport.xml",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "CloseDepositReport.xml",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 710,
        "y": 200,
        "wires": [
            [
                "cd3401a8b26eceaf"
            ],
            [
                "c756523b8691deac"
            ],
            [
                "8ee9eb2604e52aac"
            ]
        ]
    },
    {
        "id": "a7703a966d5a9e1c",
        "type": "debug",
        "z": "c672c0fdbe993a93",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 410,
        "y": 100,
        "wires": []
    },
    {
        "id": "dc3818e5.3c2fa8",
        "type": "trigger",
        "z": "c672c0fdbe993a93",
        "name": "",
        "op1": "",
        "op2": "",
        "op1type": "nul",
        "op2type": "payl",
        "duration": "5",
        "extend": true,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "topic",
        "topic": "filename",
        "outputs": 1,
        "x": 420,
        "y": 200,
        "wires": [
            [
                "ca1cdeb3151f5156"
            ]
        ]
    },
    {
        "id": "ca1cdeb3151f5156",
        "type": "file in",
        "z": "c672c0fdbe993a93",
        "name": "",
        "filename": "",
        "format": "stream",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "allProps": false,
        "x": 560,
        "y": 200,
        "wires": [
            [
                "34ab96b62d500e37"
            ]
        ]
    },
    {
        "id": "cd3401a8b26eceaf",
        "type": "xml",
        "z": "c672c0fdbe993a93",
        "name": "",
        "property": "payload",
        "attr": "",
        "chr": "",
        "x": 870,
        "y": 160,
        "wires": [
            [
                "8b2d7a5062ba8697"
            ]
        ]
    },
    {
        "id": "8b2d7a5062ba8697",
        "type": "debug",
        "z": "c672c0fdbe993a93",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1050,
        "y": 160,
        "wires": []
    },
    {
        "id": "c756523b8691deac",
        "type": "xml",
        "z": "c672c0fdbe993a93",
        "name": "",
        "property": "payload",
        "attr": "",
        "chr": "",
        "x": 870,
        "y": 200,
        "wires": [
            [
                "a13a2104215010c6"
            ]
        ]
    },
    {
        "id": "a13a2104215010c6",
        "type": "debug",
        "z": "c672c0fdbe993a93",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1050,
        "y": 200,
        "wires": []
    },
    {
        "id": "8ee9eb2604e52aac",
        "type": "xml",
        "z": "c672c0fdbe993a93",
        "name": "",
        "property": "payload",
        "attr": "",
        "chr": "",
        "x": 870,
        "y": 240,
        "wires": [
            [
                "baef2c7fe6c4522d"
            ]
        ]
    },
    {
        "id": "baef2c7fe6c4522d",
        "type": "debug",
        "z": "c672c0fdbe993a93",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1050,
        "y": 240,
        "wires": []
    }
]

Thanks again.

Impossible to tell without sample files.

However, I would start with changing the file node to read a single string

image

I think there are some conventions for xml keys:

    - Element names are case-sensitive 
    - Element names must start with a letter or underscore
    - Element names cannot start with the letters xml(or XML, or Xml, etc) 
    - Element names can contain letters, digits, hyphens, underscores, and periods 
    - Element names cannot contain spaces

so your xml files possibly don't follow the naming conventions?

additionaly to Steve-Mcls settings in my editing fields of the read file node there is one called "coding" which should be set to "utf8":

read_file

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.