Skip to content

Support encodings #258

Open
Open
@LucCappellaro

Description

@LucCappellaro

The Builder-Options allow to specify a custom encoding.
However this has no effect, except changing the xml declaration.
According to the XML spec:

... it is a fatal error for an entity including an encoding declaration
to be presented to the XML processor
in an encoding other than that named in the declaration, ...

Browsers and NodeJS support multiple encodings. It would be great if xmlbuilder-js would support this too.

To be clear, changing the encoding can have an impact on the XML representation.
Unsupported character need to be escaped with numeric character references.

Example in UTF-8:

<?xml version="1.0" encoding="UTF-8"?>
<test>
  <english>Hello World</english>
  <portuguese>Olá Mundo</portuguese>
  <czech>Ahoj světe</czech>
  <chinese>你好,世界</chinese>
</test>

Same example in ISO-8859-1:

<?xml version="1.0" encoding="ISO-8859-1"?>
<test>
  <english>Hello World</english>
  <portuguese>Olá Mundo</portuguese>
  <czech>Ahoj sv&#283;te</czech>
  <chinese>&#20320;&#22909;&#65292;&#19990;&#30028;</chinese>
</test>

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