Using Turbopower XML Partner with Delphi XE 2

1.3k Views Asked by At

We are trying to migrate our Delphi Environement from Delphi2007 to Delphi XE2. We dowloaded the latest Turbopower xml partner from Sourceforge. net. When we make a simple test to load a xml file we get an error "Invalid XML Character found" Our lines of code

var 
   testxml : UnicodeString; // a normal String in Xe2 
   FModel: TXpObjModel;
 begin 
    FModel := TXpObjModel.Create(nil); //Step 1 
    FModel.LoadMemory(testxml[1], Length(testxml)); //Step2 
 end. 

The code fails at Step 2. when the variable "Textxml" type is changed to ansiString Then the xml is loaded properly.

XML Encoding is UTF-8

something like this

<?xml version="1.0" encoding="UTF-8"> 

so can any one suggest us how to load xml data stored in Unicode string variable type?

1

There are 1 best solutions below

4
On

You can try to convert the unicode string back to UTF8, like:

var
  textxml: UnicodeString;
  textutf: UTF8String;
  FModel: TXpObjModel;
begin
  textutf := Utf8Encode(textxml);
  FModel := TXpObjModel.Create(nil); //Step 1
  FModel.LoadMemory(textutf[1], ByteLength(textutf)); //Step2
end;

Also, you should use ByteLength() function, because the real size of the string in memory is Length*SizeOf(CharType).