# Trouble converting XML

**URL:** https://discourse.nodered.org/t/trouble-converting-xml/66531
**Category:** General
**Created:** [17 August 2022 07:14 UTC](https://discourse.nodered.org/t/trouble-converting-xml/66531 "2022-08-17T07:14:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![milner236](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@milner236](https://discourse.nodered.org/u/milner236)
#### Post date: [17 August 2022 07:14 UTC](https://discourse.nodered.org/t/trouble-converting-xml/66531/1 "2022-08-17T07:14:48Z")

</div>

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:

```auto
[
    {
        "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.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [17 August 2022 07:54 UTC](https://discourse.nodered.org/t/trouble-converting-xml/66531/2 "2022-08-17T07:54:49Z")

</div>

Impossible to tell without sample files.

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/9/29943b633697b4b54917f4e596292b021013f7e1.png)

---

<div class="post-metadata">

### Author: ![knoepsche](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knoepsche/32/69450_2.png) [@knoepsche](https://discourse.nodered.org/u/knoepsche)
#### Post date: [17 August 2022 17:05 UTC](https://discourse.nodered.org/t/trouble-converting-xml/66531/3 "2022-08-17T17:05:05Z")

</div>

I think there are some conventions for xml keys:

```auto
    - 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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4b213d9c701272b4b393521bd041975ca41a0f51.jpeg)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [31 August 2022 17:05 UTC](https://discourse.nodered.org/t/trouble-converting-xml/66531/4 "2022-08-31T17:05:14Z")

</div>

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