comp.lang.ada
 help / color / mirror / Atom feed
From: mockturtle <framefritti@gmail.com>
Subject: Problems validating XML with XML/Ada
Date: Sat, 22 Mar 2014 02:51:22 -0700 (PDT)
Date: 2014-03-22T02:51:22-07:00	[thread overview]
Message-ID: <563aba6e-3f6e-4a95-a000-643ee5c43a5a@googlegroups.com> (raw)

Dear all,
I am writing a procedure that should read a configuration file in XML format.  I would like to validate the file content against a grammar, so  I followed the online documentation at http://docs.adacore.com/xmlada-docs/ but I am experiencing difficulties and now I am stuck.

At the end of this message you can find  a (self-consistent, compilable) excerpt of my code.  I get "No DTD defined for this document" at line 81 (the call to Parse, see also the embedded stack trace); however, I set the grammar with Set_Grammar, so why is it searching for a DTD?  Moreover, a Debug_Dump of the grammar returned by Parse_Scheme gives 

   Parsed location: 
   Parsed location: 

that looks a bit too terse...

Thank you in advance for any help

Riccardo


-----------------------------------
with Input_Sources.Strings;    use Input_Sources.Strings;
with Unicode.CES.Utf8;
with DOM.Readers;
with Schema.Schema_Readers;     use Schema.Schema_Readers;
with Schema.Validators;         use Schema.Validators;
with Schema.Dom_Readers;
with Ada.Characters.Latin_1;    use Ada.Characters;
with Sax.Readers;
with DOM.Core.Nodes;

procedure Prova is
   function Parse_Scheme (Str : String)
                          return Schema.Validators.XML_Grammar
   is
      Input  : String_Input;
      Parser : Schema_Reader;
   begin
      Open (Str      => Str,
            Encoding => Unicode.CES.Utf8.Utf8_Encoding,
            Input    => Input);
      
      Parser.Parse (Input);
      Close (Input);
      return Get_Grammar (Parser);
   end Parse_Scheme;

   CRLF : constant String := Latin_1.CR & Latin_1.LF;

   My_Scheme : constant String :=
                 "<?xml version=""1.0""?>" & CRLF
                 & "<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" & CRLF
                 & "   <xs:element name=""config"">" & CRLF
                 & "     <xs:complexType>" & CRLF
                 & "        <xs:sequence>" & CRLF
                 & "          <xs:element name=""dir-pair"" type=""pair-descr"" maxOccurs=""unbounded""/>" & CRLF
                 & "        </xs:sequence>" & CRLF
                 & "     </xs:complexType>" & CRLF
                 & "   </xs:element>" & CRLF

                 & "   <xs:complexType name=""keyfield"">" & CRLF
                 & "      <xs:simpleContent>" & CRLF
                 & "         <xs:extension base=""xs:string"">" & CRLF
                 & "            <xs:attribute name=""encrypted"" type=""xs:boolean"" default=""false""/>" & CRLF
                 & "         </xs:extension>" & CRLF
                 & "      </xs:simpleContent>" & CRLF
                 & "   </xs:complexType>" & CRLF

                 & "   <xs:complexType name=""pair-descr"">" & CRLF
                 & "    <xs:sequence>" & CRLF
                 & "      <xs:element name=""clearfile"" type=""xs:string""/>" & CRLF
                 & "      <xs:element name=""cypherfile"" type=""xs:string""/>" & CRLF
                 & "      <xs:element name=""key"" type=""keyfield""/>" & CRLF
                 & "    </xs:sequence>" & CRLF
                 & "   </xs:complexType>" & CRLF

                 & "</xs:schema>" & CRLF;


   Grammar : constant XML_Grammar := Parse_Scheme (My_Scheme);
   
   Data    : constant String :=
               "<?xml version=""1.0""?>" & CRLF
               & "<config>" & CRLF
               & "  <dir-pair>" & CRLF
               & "    <clearfile>/tmp/pippo.txt</clearfile>" & CRLF
               & "    <cypherfile>/dropbox/pippo.txt.enc</cypherfile>" & CRLF
               & "    <key>123456789</key>" & CRLF
               & "  </dir-pair>" & CRLF
               & "</config>" & CRLF;
   
   Input   : String_Input;
   Reader  : Schema.Dom_Readers.Tree_Reader;
begin
   Open (Str      => Data,
         Encoding => Unicode.CES.Utf8.Utf8_Encoding,
         Input    => Input);

   Reader.Set_Grammar (Grammar);
   Reader.Set_Feature (Sax.Readers.Validation_Feature, True);

   Reader.Parse (Input); -- 2:8: No DTD defined 
   -- sax/sax-readers.adb:6108
   -- sax/sax-readers.adb:979
   -- sax/sax-readers.adb:4892
   -- sax/sax-readers.adb:5949
   -- schema/schema-readers.adb:1128
   -- prova.adb:81

   Close (Input);
end Prova;
-------------------------------------------------


             reply	other threads:[~2014-03-22  9:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-22  9:51 mockturtle [this message]
2014-03-22 13:12 ` Problems validating XML with XML/Ada Alexander Senier
2014-03-22 18:52   ` mockturtle
replies disabled

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