1

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?

Warren P
  • 65,725
  • 40
  • 181
  • 316
SK9
  • 87
  • 11
  • 2
    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 Jan 06 '12 at 17:15
  • @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 Jan 06 '12 at 20:06
  • 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 Jan 06 '12 at 20:54
  • 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 Jan 09 '12 at 05:00
  • Hi there, don't forget to [`accept the answers`](http://meta.stackexchange.com/a/5235) 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 Jan 10 '12 at 22:17

1 Answers1

2

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

arthurprs
  • 4,457
  • 3
  • 26
  • 28