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

Marcos Douglas md at delfire.net
Thu Jun 16 14:51:58 CEST 2011


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

    ReadXMLFile(Doc, m);  //<<<<<<<< ERROR
  finally
    SL.Free;
    m.Free;
  end;
end.



More information about the fpc-pascal mailing list