Skip to content

Handling HTML Entities #450

@boxfoot

Description

@boxfoot

I'm using xml2js to transform an XML file that I don't have much control over. I don't want to make any changes to the XML besides the specific changes I'm trying to make.

I'm running into an issue with HTML entities where build(parse(xml)) is not a reversible process. Easiest to show with an example:

var xml2js = require('xml2js');
var builder = new xml2js.Builder({headless:true});
var xml = "<root>Hello &quot;xml2js&quot;!\r\n</root>"

xml2js.parseString(xml, function (err, result) {
    console.log(builder.buildObject(result));
});
// logs: "<root>Hello \"xml2js\"!&#xD;\n</root>"

As you can see, there are two issues here:

  1. &quot; in the input is transformed to \"
  2. \r in the input is transformed to #xD;

I've been looking through the api options and can't figure out a way to hook in and change this behavior. Any ideas, or is this a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions