Skip to content

Issue with escape character " and ' conversion for json into an xml format. #714

Open
@saba-firdos

Description

@saba-firdos

I am converting a json into an xml using xml2js.Builder and without cdata true. All tags appear correctly, except the usage of “ and ‘ escape character situated inside the tags attributed.
The Builder library is able to convert < to < and & to &
The same does not work for “ which needs to converted as &quo; and ‘ should come as &apo; .
When used anywhere in the string for eg : "aa<31&b21' it is expected to get converted as: &quot;aa&lt;31&amp;b21&apos;

Sample code to test the library.
// Create a new instance of the Builder
const builder = new xml2js.Builder();

// JavaScript object with special characters
const obj = {
root: {
name: 'John< "Doe',
age: 30,
city: 'New York'
}
};

// Convert the JavaScript object to XML
console.log(builder.buildObject(obj));

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