XML_EZ_Out(7) | Linux-XML_EZ_Out | XML_EZ_Out(7) |
XML_EZ_Out - Simple Ada utility package for generating XML output.
with McKae.XML.EZ_Out.Generic_Medium;
with McKae.XML.EZ_Out.String_Stream;
with McKae.XML.EZ_Out.Text_File;
package Ezsi is new
Mckae.Xml.Ez_Out.Generic_Medium
(Output_Medium => File_Type,
Put => Put,
New_Line => New_Line[,
Format => Spread_Indented]);
XML_EZ_Out is a small set of packages intended to aid the creation of XML-formatted output from within Ada programs. It basically wraps the tags and data provided to it with XML syntax and writes them to a user-supplied medium.
This medium can be any sort of writable entity, such as a file, a memory buffer, or even a communications link, such as a socket. The only functionality required of the medium is that it supply a meaningful "Put" (for writing a string) and "New_Line" procedure.
XML_EZ_Out package instantiations are explicitly designed to be made directly visible with the aid of a "use" clause. Declining to use a "use" will make using XML_EZ_Out inordinately verbose and awkward.
generic
type Output_Medium is limited private;
-- Output_Medium is whatever entity is going to received the formatted
-- XML output. It can be a file, a stream, a buffer, a socket, whatever.
-- All interaction with it takes place solely through the supplied Put and
-- New_Line procedures, which are modeled after the Ada.Text_IO procedures.
with procedure Put(F : in Output_Medium;
S : in String) is <>;
-- Procedure writing a string to the instantiating output medium.
with procedure New_Line (F : in Output_Medium; Spacing : in Ada.Text_IO.Positive_Count := 1) is <>;
-- Procedure writing a line break to the instantiating output medium.
Format : Formatting_Options := Spread_Indented;
-- Specify whether the XML being written is to be indented, i.e. be
-- "prettified". (DEPRECATED, control formatting by setting the
-- Current_Format variable available in the package spec.)
Max_Element_Nesting : Positive := 200;
-- The maximum element nesting depth of an XML document (used to set
-- size of tag checking stack). package McKae.XML.EZ_Out.Generic_Medium;
See the Generic_Medium package specification for details of parameters and overloaded variations.
The key facilitator of making XML_EZ_Out usage readable when generating XML documentation is the overloading of a number of variations of the "=" function. By doing this, a simple XML element having no content, such as:
<player lastName="Cuddyer" firstName="Michael" team="Twins"/>
can be generated as:
Output_Tag(F,
"player",
("lastName" = "Cuddyer",
"firstName" = "Michael",
"team" = "Twins"));
To simplify the specification of the attributes, variations of "=" are provided. Given these declarations:
One can directly reference the variables:
Batting_Average : Float;
At_Bats : Natural;
Output_Tag(F,
"stats",
("battingAvg" = Batting_Average,
"atBats" = At_Bats));
XML_EZ_Out is designed in such a way that instantiations of it are meant to be "used" by the application. When accompanied with a "use" clause, specifying the XML to be produced is very simple and clear. Insisting on using qualified names will make for very obtuse code. Likewise, "named parameter" notation would obscure the complementarity of the Ada and XML, so apply for a waiver from any such style standards.
The medium must be open and ready to accept content before invoking any of these XML output subprograms.
If the medium raises any exceptions as a result of invoking the supplied Put or New_Line procedures, those exceptions will be passed through to the caller.
Marc A. Criley, McKae Technologies (mc@mckae.com)
XML_EZ_Out does no validation of the XML content it is being asked to output, and it is possible to generate malformed documents. That includes the handling of character encoding. While XML_EZ_Out will claim the document is "UTF-8" or otherwise as set by the application, it is up to the application to ensure that correct content is provided in the strings that are passed to its various subprograms. Used appropriately, though, it can provide a clear and readable means to aid the dynamic generation of XML content by Ada programs.
2009-12-27 | Linux-XML_EZ_Out |