Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-06

In 'stream:' (line 1 pos 1): Root element is missing

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marcos Douglas

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

Marcos Douglas

Jeppe Johansen
to Marcos Douglas
Marcos Douglas wrote 11 lines
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 Marcos Douglas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Do you have an example?

Marcos Douglas
to Jeppe Johansen
Jeppe Johansen wrote 10 lines
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.
Unknown author
to Marcos Douglas
Marcos Douglas wrote 35 lines
On Thu, Jun 16, 2011 at 9:32 AM, Jeppe Johansen 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;

Michael.

Show quoted text 11 lines
ReadXMLFile(Doc, m); //<<<<<<<< ERROR finally SL.Free; m.Free; end; end. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Marcos Douglas
to Unknown author
Show quoted text 43 lines
On Thu, 16 Jun 2011, Marcos Douglas wrote: > On Thu, Jun 16, 2011 at 9:32 AM, Jeppe Johansen 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?

Marcos Douglas

Unknown author
to Marcos Douglas
Marcos Douglas wrote 47 lines
On Thu, Jun 16, 2011 at 10:44 AM, wrote: > > > On Thu, 16 Jun 2011, Marcos Douglas wrote: > >> On Thu, Jun 16, 2011 at 9:32 AM, Jeppe Johansen 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.