Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Internet/XML    [ Add a report in this area ]  
Report #:  67434   Status: Closed
TXMLDocument can not pharse XML document with non-english characters.
Project:  Delphi Build #:  12.0.3170.16989
Version:    12.0 Submitted By:   Dennies Chang
Report Type:  Basic functionality failure Date Reported:  10/2/2008 12:59:50 AM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    32 Bit Internal Tracking #:   265751
Resolution: Fixed (Resolution Comments) Resolved in Build: : 14.0.3513.24210
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
When the following codes are executing, an error poped up with message : "Invalid character in the document".

There are some Chinese text encoded by UTF8 in the document, and the codes are:


XMLDocument.XML.clear;
XMLDocument.XML.LoadFromFile(XMLFilename);
XMLDocument.Active := True;

or

XMLDocument.XML.clear;
XMLDocument.XML.LoadFromFile(XMLFilename, TEncoding.UTF8);
XMLDocument.Active := True;

Once the XMLDocument.Active is set to True, the error poped up. I can image the problem is caused by TStrings and XMLDocument internal logic conflicted.

Because classic XMLDocument used TStrings as AnsiString list, but TStrings were replaced with "TUnicodeString", so the XMLDocument logic will get unicode string to "DECODE" again.....

Therefore this error will poped up..... Please fix it ASAP, because TXMLDocument is used very frequently.
Steps to Reproduce:
None
Workarounds
None
Attachment
None
Comments

Tomohiro Takahashi at 10/3/2008 10:37:36 PM -
Could you please attach sample project to reproduce your issue?

Tomohiro Takahashi at 10/8/2008 8:50:41 PM -
With Japanese environment, we have same problem.

But, could you please try this
  XMLDocument.LoadFromFile(XMLFilename);
instead of
  XMLDocument.XML.LoadFromFile(XMLFilename);
   or
  XMLDocument.XML.LoadFromFile(XMLFilename, TEncoding.UTF8);

Dennies Chang at 11/19/2008 11:16:01 PM -
As Takahashi mentioned, I found the way to make XML work in 10/3:

    Self.XMLDocument1.Active := False;
    SElf.XMLDocument1.XML.Clear;
    Self.XMLDocument1.LoadFromFile(TargetPath);
    Self.XMLDocument1.Active := True;

This way can make TXMLDocument1 load UTF8 encoded document well, and I agree this way
is one of the solutions.

But the situation I mentioned in 10/2 still exists, and there must be many Delphi programmers used
to load XML document with  

TXMLDocument.XML.Clear;
TXMLDocument.XML.LoadFromFile(XMLFile);
TXMLDocument.Active := True;

I think that the situation should be fixed.

Server Response from: ETNACODE01