Consultor Eletrônico



Kbase P11473: When should XML-DOCUMENT:ENCODING be set?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/15/2008
Status: Verified

GOAL:

When should XML-DOCUMENT:ENCODING be set?

FIX:

The ENCODING Attribute returns the name of the character encoding used to encode the contents of an XML document (for example, UTF-8, UTF-16 and so on).

When a document is loaded using the LOAD() method, the ENCODING Attribute is set to the name specified in a document's encoding declaration.

For example:

<?xml version="1.0" encoding='UTF-8' ?>

To set the name of the desired encoding to be used when the documents SAVE() method is called, use the ENCODING Attribute.

For example:

hdoc:ENCODING = 'UTF-8'.

By default, documents written without the ENCODING Attribute set are written using an ENCODING of UTF-8.  The ENCODING Attribute should only be used when the application has specific needs that require the document to be written in another (non UTF-8) codepage, and the codepage name specified should be an IANA codepage name (Internet Assigned Numbers Authority).

Setting the ENCODING Attribute to a non-IANA codepage name, can cause the SAVE operation to fail, or if the document is written, can cause the document to be unreadable by some applications.

To set the ENCODING Attribute to the value of cpinternal, it is recommended to use the Progress utility to convert Progress specific codepage names to and from IANA names (adecomm/convcp.p).

For example:

DEFINE VARIABLE cpage AS CHARACTER NO-UNDO.
DEFINE VARIABLE iana-cpage AS CHARACTER NO-UNDO.
DEFINE VARIABLE action AS CHARACTER NO-UNDO.
DEFINE VARIABLE hdoc AS HANDLE NO-UNDO.

ASSIGN cpage = SESSION:CPINTERNAL
action = 'tomime'.

RUN adecomm/convcp.p(INPUT cpage, INPUT action, OUTPUT iana-cpage).

CREATE X-DOCUMENT hdoc.

hdoc:ENCODING = iana-cpage.