0

In the app, the table has one column named: isGlobal? and has two rows. Table data looks like this below and I would like to convert them into XML via js2xmlParser.

const row = [
      {
        'isGlobal?': 'no'
      },
      {
        'isGlobal?': 'yes'
      }
    ];
    const obj = {
      data: row
    }

js2xmlparser.parse('BBPXMLSchnittstelle', obj, {declaration: {encoding: 'UTF-8'}} );

And desired output should be :

<?xml version='1.0'?>
<root>
<data>
<isGlobal?>no</isGlobal?>
</data>
<data>
<isGlobal?>yes</isGlobal?>
</data>
</root>

But unfortunately as isGlobal? has a question mark I am getting an error.

Error: in XML document > element "root" > element "data": element name "isGlobal?" should not contain characters not allowed in XML names

Now how can I include this question mark or any special character in the XML names?

Note: I cant remove the ? mark from the data as it is collected from an HTML table whereas one column name is isGlobal?. The purpose is not to change the table information, but to convert it to XML without changing it.

Kazi
  • 1,461
  • 3
  • 19
  • 47
  • What is the reason you need the `?`? The `is` prefix already indicates that the value should be a boolean – Reyno Jul 05 '21 at 11:21
  • actually, my data is collected from a table, whereas the column name is isGlobal?. and i can't change the question mark as it represents a column @reyno – Kazi Jul 05 '21 at 11:22
  • 1
    `?` is not a valid character in an HTML `name` attribute. Use proper variable/key names from the beginning on. – Daniel W. Jul 05 '21 at 11:58

0 Answers0