Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Encoding

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Johan Strandberg <johan AT acm.org>
  • To: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • Cc: XOM Interest List <xom-interest AT lists.ibiblio.org>, Nils_Kilden-Pedersen AT Countrywide.Com
  • Subject: Re: [XOM-interest] Encoding
  • Date: Thu, 04 Sep 2003 21:29:50 -0000

On Thu, 2003-09-04 at 07:22, Elliotte Rusty Harold wrote:

> I understand the use case, but right now that's still on the other
> side of 80/20 for me. First of all, it's extremely tricky because
> documents can have both the encoding specified in the XML declaration
> and the one actually used, and these are not necessarily the same
> thing.


I assume you are talking about the case in XML1.0 section 4.3.3
[XML-433] where they discuss encoding declarations:


In the absence of information provided by an external transport
protocol (e.g. HTTP or MIME), it is an 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, or for an entity which begins with neither a Byte
Order Mark nor an encoding declaration to use an encoding other
than UTF-8. Note that since ASCII is a subset of UTF-8, ordinary
ASCII entities do not strictly need an encoding declaration.


As far as I can tell, you have exactly four cases:


1. Explicit external information provided by the transport
protocol.
2. An explicit XML declaration (EBNF rule #23 and #77) is present
and it contains an encoding declaration (EBNF rule #80).
3. An explicit XML declaration (EBNF rule #23 and #77) without an
encoding declaration
4. No information about encoding is available. (I.e., none of the
above).


In each case there is a simple strategy, so the algorithm could be
something like this (in pseudo-code):


IF there is an external encoding provided by the transport

RETURN the provided encoding (case1)

ELSE

apply table in Appendix F [XML-F]
compute tentative encoding from table
IF table indicates presence of ?xml declaration

IF xml declaration contains encoding

RETURN specified encoding (case2)

RETURN tentative encoding from table (case3&4)


Algorithmically, the only tricky one appears to be case #2, where you
have a tentative encoding provided by the tables in Appendix-F, and have
to try to extract the encoding declaration. I suspect one or several of
the open source XML parsers out there have a code snippet to borrow.

As to an API for XOM, case #1 isn't very interesting. If the user knows
the encoding, XOM doesn't have to do anything. Otherwise just provide a
method that returns an encoding given an input source (I.e., the same
set of arguments provided by the various declarations of
nu.xom.Build.build(...) ).


--j


[XML-433] Extensible Markup Language (XML) 1.0 (Second Edition),
Section 4.3.3 - Character Encoding in Entities
http://www.w3.org/TR/REC-xml#charencoding

[XML-F] Extensible Markup Language (XML) 1.0 (Second Edition),
Appendix F - Autodetection of Character Encodings (Non-Normative)
http://www.w3.org/TR/REC-xml#sec-guessing




Archive powered by MHonArc 2.6.24.

Top of Page