Menu

#3 Xml read fails when xml uses windows code page 1252 instead of utf8

2.0
rejected
nobody
None
2014-11-27
2014-11-26
No

Hi

We've just started using OXML and have found it great so far - significantly faster than NativeXML :-)

We have encountered a problem parsing an XML that specifies Windows-1252 encoding. Delphi XE6 throws an encoding exception that causes it to fail loading the stream.

I had a quick look at the code and added a simple exception catch to work around the problem.

Index: OTextReadWrite.pas

--- OTextReadWrite.pas (revision 7872)
+++ OTextReadWrite.pas (working copy)
@@ -656,11 +656,21 @@

Inc(fStreamPosition, xReadBytes+xUTF8Inc);
SetLength(xBuffer, xReadBytes+xUTF8Inc);

  • {$IFDEF O_DELPHI_2009_UP}
  • fTempString := fEncoding.GetString(xBuffer);
  • {$ELSE}
  • fEncoding.BufferToString(xBuffer, fTempString);
  • {$ENDIF}
  • try
  • {$IFDEF O_DELPHI_2009_UP}
  • fTempString := fEncoding.GetString(xBuffer);
  • {$ELSE}
  • fEncoding.BufferToString(xBuffer, fTempString);
  • {$ENDIF}
  • except
  • On EEncodingError do
  • begin
  • ; // ignore this, we'll try again for some other code page below
  • end
  • else
  • raise;
  • end;
    +
    if (Length(xBuffer) > 0) and (fTempString = '') then
    begin
    //must be here -> default is UTF-8 -> if BOM not set and codepage is some ANSI, UTF-8 returns empty string -> try ASCII and read codepage from tag afterwards

Discussion

  • Ondrej Pokorny

    Ondrej Pokorny - 2014-11-27

    You've been using an old version of OXml. This bug has already been fixed. Please update OXml.

     

    Last edit: Ondrej Pokorny 2014-11-27
  • Ondrej Pokorny

    Ondrej Pokorny - 2014-11-27
    • status: open --> rejected
     
  • Mark Kendall

    Mark Kendall - 2014-11-27

    Sorry about that, I had a quick look at the sourceforge code before raising the ticket and it looked the same around there. I'll try a checkout instead of the downloaded version. Thanks.

     
  • Ondrej Pokorny

    Ondrej Pokorny - 2014-11-27

    No problem. The SVN version should now be the same as the downloaded version (1.2).

    Please confirm that the bug has been fixed (I hope I haven't been wrong about that).

     
  • Mark Kendall

    Mark Kendall - 2014-11-27

    I'm not encountering the error so I think it's fine, thanks.

     

Log in to post a comment.