[fpc-pascal] In 'stream:' (line 1 pos 1): Root element is missing

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Thu Jun 16 16:30:07 CEST 2011



On Thu, 16 Jun 2011, Marcos Douglas wrote:

> On Thu, Jun 16, 2011 at 10:44 AM,  <michael.vancanneyt at wisa.be> wrote:
>>
>>
>> On Thu, 16 Jun 2011, Marcos Douglas wrote:
>>
>>> On Thu, Jun 16, 2011 at 9:32 AM, Jeppe Johansen <jepjoh2 at es.aau.dk> wrote:
>>>>
>>>> Den 16-06-2011 14:09, Marcos Douglas skrev:
>>>>>
>>>>> I am using the xmlread.ReadXMLFile(doc, stream) function to read a XML.
>>>>> If I use a file works OK.
>>>>> If I use a Stream of the same file (I saved the Stream in a file and
>>>>> compare with de original file... are equal), happen an error:
>>>>>
>>>>> In 'stream:' (line 1 pos 1): Root element is missing
>>>>
>>>> Do you have an example?
>>>
>>> Yes, see:
>>>
>>> program t_xml;
>>>
>>> {$mode objfpc}{$H+}
>>>
>>> uses classes, sysutils, dom, XMLRead;
>>>
>>> const
>>>  FILE_NAME = 'test.xml';
>>> var
>>>  Doc: TXMLDocument;
>>>  SL: TStringList;
>>>  m: TMemoryStream;
>>> begin
>>>  ReadXMLFile(Doc, FILE_NAME);   //<<<<<<< OK
>>>  Doc.Free;
>>>
>>>  m := TMemoryStream.Create;
>>>  SL := TStringList.Create;
>>>  try
>>>   SL.LoadFromFile(FILE_NAME);
>>>   SL.SaveToStream(m);
>>
>> Add here
>>  M.Position:=0;
>
> Correct!
> Thanks... but the ReadXMLFile() should do it, don't?

No. For some streams, this will give an exception.

Michael.


More information about the fpc-pascal mailing list