This is not directly related to current development, but it is something 
that might need a low-level solution.  I've been thinking for some time 
about how to enchance the current "XML support" (e.g., contrib/xml).

The central problem I have is this:  How do we deal with the fact that 
an XML datum carries its own encoding information?

Here's a scenario:  It is desirable to have validity checking on XML 
input, be it a special XML data type or some functions that take XML 
data.  Say we define a data type that stores XML documents and rejects 
documents that are not well-formed.  I want to insert something in 
psql:

CREATE TABLE test (
    description text,
    content xml
);

INSERT INTO test VALUES ('test document', '<?xml 
version="1.0"?><doc><para>blah</para>...</doc>');

Now an XML parser will assume this document to be in UTF-8, and say at 
the client it is.  What if client_encoding=UNICODE but 
server_encoding=LATIN1?  Do we expect some layer to rewrite the <?xml?> 
declaration to contain the correct encoding information?  Or can the 
xml type bypass encoding conversion?  What about reading it back out of 
the database with yet another client encoding?

Rewriting the <?xml?> declaration seems like a workable solution, but it 
would break the transparency of the client/server encoding conversion.  
Also, some people might dislike that their documents are being changed 
as they are stored.

Any ideas?


Fri, 9 Jan 2004 19:46:01 +0100
Peter Eisentraut <peter_e@gmx.net>
Encoding problems in PostgreSQL with XML data
> Rewriting the <?xml?> declaration seems like a workable solution, but it 
> would break the transparency of the client/server encoding conversion.  
> Also, some people might dislike that their documents are being changed 
> as they are stored.

I presume that the XML type stores the textual representation of the XML
rather than a binary (parsed) format?

I say we treat XML the same was as we deal with things like float and
allow some play with the stored object so long as it's reasonably small
and has the same final interpretation.

If they wanted non-mutable text, they would not have declared it as a
structured format. Just like if they don't want leading 0's removed from
numeric input, they don't declare it as numeric but as binary.


Fri, 09 Jan 2004 14:21:50 -0500
Rod Taylor <pg@rbt.ca>
Re: Encoding problems in PostgreSQL with XML data