Re: Bug in Mozilla parser
Peter Flynn <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.xml |
|---|---|
| Organization | Usenet Labs Bozon Detector Facility |
| Message-ID | <[email protected]> |
Vinu wrote: > Hi, > > I am using the mozilla parser originally written by JamesClark. > I set the encoding to latin_1. > > My xml buffer contains some characters greater than Ascii code 128. But > these are in the CDATA sections. Doesn't matter. A character in the document is a character in the document, even if it's in a CDATA section or a comment. > Now my XML buffer is clearly in latin_1 or ASCII encoding. No, specifying <?xml version="1.0" encoding="iso-8859-1"?> just says that you *claim* it's all Latin-1; it doesn't guarantee or check it. > So when the > parser encounters these characters(ASCII code > 128), it uses two bytes > to represent it rather than the one byte used for latin1. You mean the parser encounters two bytes where you were expecting your document to use only one? > This is obvioulsy a UTF-8 representation. Possibly. > But i have clearly set the encoding as latin1. Then why is this > happening. Whatever process generates your XML (hand-edit? program? download?) is storing the character in a character encoding other than ISO 8859-1. You need to find out where the data is coming from and fix it. > Also isnt the parser supposed to ignore anything in the CDATA section. No, a CDATA section only stops the parser scanning for markup characters. The content still has to be in the document character set. > Is this a well known bug. No, but it is a common problem, usually due to the XML document being stored in a different encoding to the one you are expecting. > Could somebody please suggest something on > this. If you're using a Unix-based system (Mac, Linux, etc), and if you are positive that the offending character has a representation in ISO 8859-1, use the iconv program to force the document to be stored as such, eg $ iconv -t iso-8859-1 myfile.xml >newfile.xml If the character has no representation in ISO 8859-1 you'll get an error message, and you'll have to use UTF-8 or something else instead. I don't know how you do this under Windows, though. ///Peter