Sign in Join

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

Mailing lists / lazarus / 2010-02

xml reading problem

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Andrea Mauri

dear all,
I have some problems reading xml files.
If I read xml files using ReadXMLFile it works only if I use:
1. procedure ReadXMLFile(out ADoc: TXMLDocument; const AFilename: String); overload;
while if I use
2. procedure ReadXMLFile(out ADoc: TXMLDocument; var f: Text); overload; the program crashes.

I attached two files (acetyl.cml and acetyl2.cml). The second one is always read properly, the first one is read properly only if I use procedure 1.
In order to reproduce the error just create a new project, put a button and two tedit on the form.
In the button1 click put this code:

procedure TForm1.Button1Click(Sender: TObject);
var
   F: TextFile;
   FileName: String;
   XMLMolDoc: TXMLDocument;
   XMLMols: TDOMNodeList;
begin
   FileName:= Edit1.Text;
   //AssignFile(F, FileName);
   //Reset(F);
   //ReadXMLFile(XMLMolDoc, F);
ReadXMLFile(XMLMolDoc, FileName);
   XMLMols:= XMLMolDoc.GetElementsByTagName('molecule');
   edit2.text:= IntToStr(XMLMols.Count);
   //ClosefILE(F);
end;

With this code it works.

While if I put this:

procedure TForm1.Button1Click(Sender: TObject);
var
   F: TextFile;
   FileName: String;
   XMLMolDoc: TXMLDocument;
   XMLMols: TDOMNodeList;
begin
   FileName:= Edit1.Text;
   AssignFile(F, FileName);
   Reset(F);
   ReadXMLFile(XMLMolDoc, F);
   XMLMols:= XMLMolDoc.GetElementsByTagName('molecule');
   edit2.text:= IntToStr(XMLMols.Count);
   ClosefILE(F);
end;

It crashes raising: exception class 'EXMLreaderror' with message: In 'file:///e:/temp/acetyl.cml' (line 1 pos 21): expected "?>"

Why?
Andrea

-------------- next part --------------
A non-text attachment was scrubbed...
Name: acetyl2.cml
Type: text/xml
Size: 1498 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100215/c355e9e1/attachment.xml> -------------- next part --------------
A non-text attachment was scrubbed...
Name: acetyl.cml
Type: text/xml
Size: 1937 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100215/c355e9e1/attachment-0001.xml>

Reply by email

Marco van de Voort
to Andrea Mauri
Andrea Mauri wrote 6 lines
I attached two files (acetyl.cml and acetyl2.cml). The second one is always read properly, the first one is read properly only if I use procedure 1. In order to reproduce the error just create a new project, put a button and two tedit on the form. In the button1 click put this code:

I think you have found a bug.

Please convert the examples to working console programs, and attach them to a bugreport in Mantis. (and the acetyl* files as well)

Reply by email

Andrea Mauri
to Andrea Mauri

Il 15/02/2010 16.31, Andrea Mauri ha scritto:

Show quoted text 6 lines
> Please convert the examples to working console programs, and attach them > to a bugreport in Mantis. (and the acetyl* files as well) >

I reported it as Bug 0015776 [FPC] FCL
Thanks,
andrea

Reply by email

Sergei Gorelkin
to Andrea Mauri
Andrea Mauri wrote
I reported it as Bug 0015776 [FPC] FCL Thanks, andrea

Fixed in r14919.

Note, however, that using TextFile-based ReadXMLFile overloaded variant is somewhat discouraged, because it is slower than other variants and is not able to handle utf-16 encodings.

Sergei

Reply by email