[DUG] Strange Error in Android
Jolyon Smith
jsmith at deltics.co.nz
Fri Dec 6 15:25:34 NZDT 2013
Also, to fix the problem you can avoid the bug by ensuring that your
string is loaded via the stream based code path by ensuring that your
UTF-8 encoded XML is not using the inappropriate
WideString/DOMString/UnicodeString type, but the more appropriate
ANSIString/UTF8String type.
This is why CheckEncoding is trying to remove the encoding declaration
from the XML string in the first place: the string based loading path
only supports WideStrings, only Wide encodings are supported (UTF-16,
UCS-2 etc).
Unfortunately, in your case, things aren't quite so simple because the
ANSIString version of LoadXMLData is not supported by NEXTGEN compilers,
of which the Android compiler is one.
This means that you can't use the LoadXMLData() convenience method and
will instead have to instantiate a TXMLDocument yourself. Even then,
the ANSIString version of LoadFromXML() is again not supported on
NEXTGEN compilers, so to trigger a codepath that does not invoke
CheckEncoding you will have to use the XML TStrings property:
doc := TXMLDocument.Create;
doc.XML.Text := myXMLString;
I haven't checked to see whether assigning a WideString XML string that
contains an encoding declaration that identifies UTF-8 (incorrectly)
will cause problems if the DOM implementation then attempts to respect
the declared encoding (since the stringlist code path will leave the XML
encoding declaration intact and process the XML string itself as a
WideString, contrary to the declared encoding).
Perhaps the safest approach, given that unless you have taken specific
steps to ensure otherwise, your string is almost certainly a WideString
and so the UTF-8 encoding declaration is indeed incorrect, would be to
remove the encoding yourself using a more robust method than
CheckEncoding() employs, and ensure that you remove the encoding before
passing it to LoadXMLData().
If it were me I would simply use the platform's own XML support, but
that is even more difficult given that you are using Delphi for your
Android code so access to those platform capabilities is even more
difficult than wrestling with the mess that String support has become in
Delphi these days.
Good luck.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20131206/1a11a083/attachment-0001.html
More information about the Delphi
mailing list