SAX2 parsing using SAX.pp lazarus / 13-General ---------------------------------------------------------------------- Fadetoblack · 2006-03-11 12:59 Hello, I'm fairly new to object pascal programming. Though i have use delphi before(i was more of a VB user). But here's my problem. I'm trying to parse a xml document using SAX. So at the moment i'm trying to use the SAX unit provided with Lazarus. Sadly though there's absolutly no documentation on this unit. I think i finally got it so far as to set the Reader instance which events to catch. But if i run the program i get an Access violation error(Acces Violation Press Ok to continue and risk loss of data etc etc) Here's a part of hte code:(i'm just trying to do a basic thing as to read the element names from the xml file). procedure TForm1.MyStartElementEvent(Sender: TObject; const NamespaceURI, LocalName, QName: SAXString; Atts: TSAXAttributes); begin     form1.ListBox1.Items.Add(QName); end; procedure TForm1.Button1Click(Sender: TObject); var XMLReader:TSAXReader; begin    If (OpenDialog1.Execute) then    begin         XMLReader.OnStartElement:=@MyStartElementEvent;         XMLReader.Parse(OpenDialog1.Filename);         XMLReader:=nil;    end; end;                             Hope you can help me out. Kind regards, Fade ---------------------------------------------------------------------- Fadetoblack · 2006-03-12 11:36 Hasn't anyone ever used the SAX unit ?    Please i need to get this to work ---------------------------------------------------------------------- felipemdc · 2006-03-12 13:02 Do you really need to use SAX or any xml parsing unit will do? There is a short example about DOM here: http://wiki.lazarus.freepascal.org/index.php/Networking#XML ---------------------------------------------------------------------- Fadetoblack · 2006-03-12 13:31 I really need to use SAX since they are big xml files. If i use dom the memory requirements would be insane And also SAX is waay faster in parsing. ---------------------------------------------------------------------- Bart · 2006-03-12 17:33 Quote from: "Fadetoblack" Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var XMLReader:TSAXReader; begin    If (OpenDialog1.Execute) then    begin         XMLReader.OnStartElement:=@MyStartElementEvent;         XMLReader.Parse(OpenDialog1.Filename);         XMLReader:=nil;    end; end; Just a wild quess, you forgot to create the XMLReader object? Try something like: Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var XMLReader:TSAXReader; begin    If (OpenDialog1.Execute) then    begin         XMLReader := TSAXReader.Create;  //do'nt know if it needs parameters         try           XMLReader.OnStartElement:=@MyStartElementEvent;           XMLReader.Parse(OpenDialog1.Filename);           //XMLReader:=nil;         finally            XMLReader.Free          end;    end; end; Bart ---------------------------------------------------------------------- Fadetoblack · 2006-03-12 19:23 Hmm i thought i tried that before but i guess i didnt. But now at least i dont get a access violation error on XMLReader.OnEvent But i get a 'abstract method called’ error now. Also with a yes or no button that warn you about corruption of data. -Fade- ---------------------------------------------------------------------- bonmario · 2006-11-15 07:36 Hi, someone have used SAX in Lazarus for read files XML? I have tryed the code of previous post but i have a "Runerror(211)". Someone can post a simple example for read a file XML with SAX?? Thanks, Mario