How to include special charecter in xml names using js2XmlParser?

132 views Asked by At

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.

0

There are 0 answers