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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!matrix.darkstorm.co.uk!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: J Kimball Newsgroups: comp.lang.ada Subject: Re: Generating an XML DOM tree from scratch withXML/Ada 2013 Date: Fri, 21 Mar 2014 11:12:11 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <1f79df5e-7fbd-4f94-b2c7-8afa754b31d5@googlegroups.com> NNTP-Posting-Host: wsip-70-184-216-60.om.om.cox.net Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: loke.gir.dk 1395418333 25143 70.184.216.60 (21 Mar 2014 16:12:13 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Fri, 21 Mar 2014 16:12:13 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Thunderbird/27.0 In-Reply-To: <1f79df5e-7fbd-4f94-b2c7-8afa754b31d5@googlegroups.com> Xref: news.eternal-september.org comp.lang.ada:18903 Date: 2014-03-21T11:12:11-05:00 List-Id: On 03/20/2014 12:00 PM, Marc C wrote: > After writing up some pathfinding code to simply create a DOM document tree from scratch, add a node, and write it out, I was perplexed that the namespace data I was supplying was not showing up in the document. > > Imagine my surprise when looking at the Dom.Core.Create_Document() implementation and seeing that the Namespace_URI (and Qualified_Name) parameters are simply ignored. The comment in the spec simply states "Note that Namespace_URI can be the empty string if you do not want to use namespaces." > > Well, I *do* want (and need) to use namespaces. > > The implementation of various subprograms reference namespaces and qualified names, and that seems to somehow tie into the SAX Symbol_Table that can be provided to Create_Document. But it ain't clear what one would have to do in that regard, not to mention I'm not sure I'm even reading the code right about all that. > > I've got XML_EZ_Out for outputting XML, but in this instance I preferred to build the DOM tree and manipulate it, then write the whole thing out when I was done. > > Anyone used the GNAT GPL 2013 XML/Ada packages for creating DOM trees with namespaces? > > Thanks. > > Marc A. Criley > I have done this. The organization and documentation of XML is perplexing and I've also spent hours banging my head against a wall trying to use namespaces and validation. Here's a result of my labor. I hope you can make some sense of it. Unfortunately, I couldn't find the input files that i was using to test. There are two command line arguments. I think the first is the xml file and the second is a valid XSD schema. Good luck. -- with Ada.Command_Line; with Ada.Directories; with Ada.Direct_IO; with Ada.Exceptions; with Ada.Text_IO; with DOM.Core.Elements; with DOM.Core.Nodes; with Input_Sources.File; with Input_Sources.Strings; with SAX.Readers; with Schema.DOM_Readers; with Schema.Schema_Readers; with Schema.Validators; with Unicode.CES.Utf8; procedure Validate_Message is Grammar : Schema.Validators.XML_Grammar; Agent_NS : String := "http://example.com/schemas/agent"; function Get_Message (XML : String) return String is Input : Input_Sources.Strings.String_Input; Reader : Schema.DOM_Readers.Tree_Reader; Document : DOM.Core.Document; Elements : DOM.Core.Node_List; begin Input_Sources.Strings.Open (Str => XML, Encoding => Unicode.CES.Utf8.Utf8_Encoding, Input => Input); Schema.DOM_Readers.Set_Grammar (Reader, Grammar); Schema.DOM_Readers.Set_Feature (Reader, SAX.Readers.Namespace_Prefixes_Feature, True); Schema.DOM_Readers.Set_Feature (Reader, SAX.Readers.Namespace_Feature, True); -- Schema.DOM_Readers.Set_Feature (Reader, SAX.Readers.Validation_Feature, True); Schema.DOM_Readers.Parse (Reader, Input); Input_Sources.Strings.Close (Input); Document := Schema.DOM_Readers.Get_Tree (Reader); Schema.DOM_Readers.Free (Reader); Elements := DOM.Core.Elements.Get_Elements_By_Tag_Name_NS (Elem => Document, Namespace_URI => Agent_NS, Local_Name => "message"); return DOM.Core.Nodes.Node_Value (DOM.Core.Nodes.Item (Elements, 0) ); exception when E : others => Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Information (E) ); raise; end Get_Message; function Init_Grammar return Schema.Validators.XML_Grammar is Reader : Schema.Schema_Readers.Schema_Reader; Input : Input_Sources.File.File_Input; begin Input_Sources.File.Open (Ada.Command_Line.Argument (2), Input); Schema.Schema_Readers.Parse (Reader, Input); Input_Sources.File.Close (Input); return Schema.Schema_Readers.Get_Grammar (Reader); end Init_Grammar; File_Size : Ada.Directories.File_Size := Ada.Directories.Size (Ada.Command_Line.Argument (1) ); subtype File_Input is String (1..Integer (File_Size) ); package File_IO is new Ada.Direct_IO (Element_Type => File_Input); File : File_IO.File_Type; Input : File_Input; begin Schema.Set_Debug_Output (True); -- Schema.Dump_Internal_XSD := True; File_IO.Open (File => File, Mode => File_IO.In_File, Name => Ada.Command_Line.Argument (1) ); File_IO.Read (File => File, Item => Input); File_IO.Close (File => File); Grammar := Init_Grammar; Ada.Text_IO.Put_Line (Get_Message (Input) ); end Validate_Message;