1
votes

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
Can I suggest you just drop Turbo Power XML partner and go to OmniXML which does not require you to invoke untyped parameters and handle byte-buffer management yourself. What an ugly API. - Warren P
@WarrenP is spot on here. The Turbo Power stuff is dead, and you should really try to move to an actively maintained XML lib. - David Heffernan
It occurs to me that while XML Partner COMPILES fine now in Delphi 2009 and XE, and XE2, it may not have even been made fully Unicode aware, and Unicode capable. Such things should not be assumed, especially on old no-longer-actively-used-by-anybody technology. - Warren P
Thanks all for your suggestions. For now we will look into the options of the OmniXML. One more question on Hyperstr unit. Has any one made any changes to make it comaptible with Delphi Xe2 or Delphi 2009. We use the Hypestr unit for faster string manipulations. Or can anyone suggest any alternative for Hyperstr. - SK9
Hi there, don't forget to accept the answers which helped you to solve the problems you've had. And please ask another question about the Hyperstr, this question already had its top of the fame. And I ♥ OmniXML ;) - TLama

1 Answers

2
votes

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).