From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,d4ae576545d491bc X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.180.10.230 with SMTP id l6mr3637948wib.3.1366082464705; Mon, 15 Apr 2013 20:21:04 -0700 (PDT) Path: hg5ni6313wib.1!nntp.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!border2.nntp.ams2.giganews.com!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news.teledata-fn.de!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!news.jacob-sparre.dk!hugin.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: J Kimball Newsgroups: comp.lang.ada Subject: Re: XML/Ada schema validation and XML namespaces Date: Wed, 10 Apr 2013 12:42:26 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: NNTP-Posting-Host: wsip-70-184-216-59.om.om.cox.net Mime-Version: 1.0 X-Trace: hugin.sparre-andersen.dk 1365615747 7482 70.184.216.59 (10 Apr 2013 17:42:27 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Wed, 10 Apr 2013 17:42:27 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Date: 2013-04-10T12:42:26-05:00 List-Id: On 04/09/2013 06:45 AM, Simon Wright wrote: > J Kimball writes: > >> I'm having the derndest time figuring out how to validate XML using >> namespaces against a schema with XML/Ada. I seem to recall that doing >> away with namespaces makes it work. After all the debug junk I don't >> care about scrolls past, I see: >> >> Validation_Error: Attribute "xmlns:agent" invalid for type >> {http://singo1.com/schemas/agent}agent-message >> Exception name: SCHEMA.VALIDATORS.XML_VALIDATION_ERROR >> >> it seems like an issue with XML/Ada. Can you tell me if I'm missing a >> feature to enable, something about XML that I'm missing or just wrong >> code or an example that is using namespaces that works? > > I think you may have been using the AdaCore documentation at [1]? > > If so, I think the problem is that the examples in 6.4, 6.5 don't > actually set the grammar to be used by the reader; in 6.3 there's a > declare block which shows you how to do it, eg > > with Sax.Readers; use Sax.Readers; > with Schema.Readers; use Schema.Readers; > with Schema.Schema_Readers; use Schema.Schema_Readers; > with Schema.Validators; use Schema.Validators; > with Input_Sources.File; use Input_Sources.File; > > with Ada.Text_IO; use Ada.Text_IO; > > procedure SchemaExample is > Grammar : XML_Grammar; > Schema : Schema_Reader; > Input : File_Input; > My_Reader : Validating_Reader; > begin > Open ("agent.xsd", Input); > Parse (Schema, Input); > Close (Input); > > Grammar := Get_Grammar (Schema); > > Set_Public_Id (Input, "Agent file"); > Open ("agent.xml", Input); > > Set_Grammar (My_Reader, Grammar); > Set_Feature (My_Reader, Schema_Validation_Feature, True); > Parse (My_Reader, Input); > > Close (Input); > > Put_Line ("OK."); > end SchemaExample; > > which outputs "OK.". > > I'm about to report this problem to AdaCore. > > [1] http://docs.adacore.com/xmlada-docs/schema.html > I get the same result when using your example. But when I try to fetch elements from the DOM tree (Source is below), I get exceptions. For this demo I've dumped the files into strings so the barrier to testing is lower. Looking at XML documentation, local name doesn't include a prefix and the namespace URI is obvious. I compile with: % gnatmake -gnatf -v -s -g -p -P schemaexample -bargs -E When I run it I receive this: % ./schemaexample Execution terminated by unhandled exception Exception name: CONSTRAINT_ERROR Message: schemaexample.adb:59 discriminant check failed Call stack traceback locations: 0x403b9f 0x4035f7 0x7fd1773c8eab 0x402b5b % addr2line --demangle=gnat --functions --exe=schemaexample 0x403b9f 0x4035f7 0x7fb3dfc66eab 0x402b5b schemaexample /home/jkimball/websockets/schemaexample.adb:59 main /home/jkimball/websockets/b~schemaexample.adb:508 ?? ??:0 <_start> ??:0 I'm working on a debug version of XML/Ada so the second half of these addresses mean something to addr2line. with Sax.Readers; use Sax.Readers; with Schema.Readers; use Schema.Readers; with Schema.Schema_Readers; use Schema.Schema_Readers; with Schema.Validators; use Schema.Validators; with Input_Sources.Strings; use Input_Sources.Strings; with DOM.Core; use DOM.Core; with DOM.Core.Elements; with DOM.Core.Nodes; with Ada.Text_IO; use Ada.Text_IO; with Schema.DOM_Readers; use Schema.DOM_Readers; with Unicode.CES.Utf8; procedure SchemaExample is XSD : constant String := "" & "" & " " & " " & " " & " " & " " & " " & " " & ""; XML : constant String := "" & "" & " Zerg" & ""; Grammar : XML_Grammar; S_Reader : Schema_Reader; Input : String_Input; My_Reader : Schema.DOM_Readers.Tree_Reader; Document : DOM.Core.Document; Messages : DOM.Core.Node_List; Length : Natural; Agent_NS : constant String := "http://singo1.com/schemas/agent"; begin Input_Sources.Strings.Open (Str => XSD, Encoding => Unicode.CES.Utf8.Utf8_Encoding, Input => Input); Parse (S_Reader, Input); Close (Input); Grammar := Get_Grammar (S_Reader); Set_Public_Id (Input, "Agent file"); Input_Sources.Strings.Open (Str => XML, Encoding => Unicode.CES.Utf8.Utf8_Encoding, Input => Input); Set_Grammar (My_Reader, Grammar); Set_Feature (My_Reader, Schema_Validation_Feature, True); Parse (My_Reader, Input); Close (Input); Document := Schema.DOM_Readers.Get_Tree (My_Reader); Messages := DOM.Core.Elements.Get_Elements_By_Tag_Name_NS (Elem => Document, Namespace_URI => Agent_NS, Local_Name => "message"); Length := DOM.Core.Nodes.Length (Messages); Schema.DOM_Readers.Free (My_Reader); DOM.Core.Free (Messages); Put_Line ("OK."); end SchemaExample;