Re: asymmetry between serialzier and parser inwritingXMLDecl
Aleksander Slominski <[email protected]>
| Newsgroups | gmane.text.xml.xmlpull.devel |
|---|---|
| Message-ID | <[email protected]> |
Elliotte Rusty Harold wrote: > At 11:52 AM -0400 8/27/02, Aleksander Slominski wrote: > > > # encoding: obtained from getInputEncoding() > > null if stream had unknown encoding (not set in setInputStream) > > and it was not declared in XMLDecl > > > > This one's tricky. The stream did have some encoding, even if it > wasn't declared, or you couldn't have decoded it. So you might want > to use "UTF-8" here instead of null. that is why we have getInputEncoding() that can be used to retrieve what was encoding passed in as parameter to setInput(InputStream in, String encoding). what i described is to use getInputEncoding() to report XMLDecl encoding if there was XMLDecl and there was no encoding defined in setInput(). > You also have to consider the possibility that the declared encoding > is not the actual encoding. This is possible in the presence of > external metadata such as an HTTP header which identifies the > encoding. For instance, even if the document is written in SJIS while > the encoding declaration specifies "UTF-16" the document might still > be successfully parsed if the metadata says SJIS. you are right. if encoding information is present in XMLDecl and as well was passed in setInput() than parser will need to resolve which one is authoritative and report when asked by calling getInputEncoding(). this process should follow http://www.w3.org/TR/REC-xml#sec-guessing-no-ext-info (see Note about checking encoding in XMLDecl) thanks, alek