1
votes

I migrated my Delphi 7 code to Delphi XE4. I am getting error in the LoadFromStram method in Delphi XE4 but same is working fine for Delphi 7.

Error:

First chance exception at $7559C41F. Exception class EDOMParseError with message
'XML document must have a top level element.

Line: 0
'.
Process abc.exe (10516)


var
myStream : TStream;
....
....
LoadFromStream(myStream);

I am using XMLDoc, XMLIntf, XMLDOM in uses clause.

1
Have you set the stream Position to 0 ? - TLama
@TLama - where to specify Position? - user1556433
Use e.g. myStream.Position := 0;, but it doesn't have to be your problem. That stream can be empty as Chris pointed out. You can check that if you evaluate myStream.Size property. If it's 0, then you have an empty stream and thus an invalid XML. - TLama
@TLama - Position is already set to 0. While loading the same XML in Delphi 7, the xml size is not zero, but loading same xml from Delphi XE4 code, xml size becomes zero. What could be the reason? - user1556433
Sorry, but I have absolutely no idea. I don't how do you fill that stream. I'd suspect it's something related to ANSI/Unicode migration, but it's just a wild guess. - TLama

1 Answers

3
votes

Your stream is either empty (like you loaded from an invalid file, or whatever, you don't give enough code to tell us how you populated the stream), or as TLama pointed out, you didn't reset to the beginning. i.e. seek(0);