comp.lang.ada
 help / color / mirror / Atom feed
From: Serge Robyns <serge.robyns@gmail.com>
Subject: Re: Trying to make XMLada use a validating SAX Parser
Date: Fri, 5 Jun 2015 08:47:21 -0700 (PDT)
Date: 2015-06-05T08:47:21-07:00	[thread overview]
Message-ID: <d77c6b35-38f3-4cf7-8f73-0724ce4f859f@googlegroups.com> (raw)
In-Reply-To: <lyh9qnw3h9.fsf@pushface.org>

Dear Simon,

Thank you very much for the hint.  It does indeed work as suggested.

It is very disappointing that the "official" documentation of Ada Core does described "legacy". Going through almost 200 sources files is not the ideal way to achieve success.  I've been wasting many evening hours trying to figure out this issue.  Such hurdles will certainly not help attracting people to Ada.  If I wasn't convinced about code and language quality I would have given up and used more hype languages.

Below the code that does do all what I want (well here only debugging as creating objects from XML will be fine).  I share this so others could stumble on it when Google-ing.

=== MyXML.ads ===
with Sax.Readers;
with Sax.Utils;
with Sax.Symbols;
with Schema.Readers;

package MyXML is
   -- type MyReader is new Sax.Readers.Sax_Reader with null record;
   type MyReader is new Schema.Readers.Validating_Reader with null record;

   overriding procedure Start_Element
     (Handler    : in out MyReader;
      NS         : Sax.Utils.XML_NS;
      Local_Name : Sax.Symbols.Symbol;
      Atts       : Sax.Readers.Sax_Attribute_List);

end MyXML;

=== MyXML.adb ==
with Ada.Text_IO; use Ada.Text_IO;

package body MyXML is

   procedure Start_Element
     (Handler    : in out MyReader;
      NS         : Sax.Utils.XML_NS;
      Local_Name : Sax.Symbols.Symbol;
      Atts       : Sax.Readers.Sax_Attribute_List) is
   begin
      Put_Line (Sax.Symbols.Debug_Print (Local_Name));
      for I in 1 .. Sax.Readers.Get_Length (Atts) loop
         Put_Line (Sax.Symbols.Debug_Print (Sax.Readers.Get_Value (Atts, I)));
      end loop;
   end Start_Element;

end MyXML;


=== SaxTester.adb ===
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Exceptions;

with Input_Sources.File;
with Sax;
with Sax.Readers;
with Schema.Validators;

with MyXML; use MyXML;

procedure SaxTester is
   Input     : Input_Sources.File.File_Input;
   My_Reader : MyReader;
begin
   Put_Line ("Start");

   Input_Sources.File.Open ("transactions.xml", Input);
   My_Reader.Set_Feature (SAX.Readers.Schema_Validation_Feature, True);
   My_Reader.Parse (Input);
   Input.Close;

exception
   when Schema.Validators.XML_Validation_Error
      => Put_Line ("Invalid transaction file!");
      raise;
   when Except_ID : others
      => Put_Line ("Got Exception");
      Put_Line (Ada.Exceptions.Exception_Information (Except_ID));

end SaxTester;


  reply	other threads:[~2015-06-05 15:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-04 20:59 Trying to make XMLada use a validating SAX Parser Serge Robyns
2015-06-04 21:47 ` Simon Wright
2015-06-05 15:47   ` Serge Robyns [this message]
2015-06-05 17:50     ` David Botton
2015-06-05 23:33       ` Vadim Godunko
2015-06-06  8:22       ` Pascal Obry
2015-06-06 10:04         ` Serge Robyns
2015-06-07  3:42           ` David Botton
2015-06-07  7:19             ` Simon Wright
2015-06-07 12:00               ` David Botton
2015-06-07  3:29         ` David Botton
2015-06-08 22:45 ` wowwomenonwheels205
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox