Functional Logo Perl                  
history | edit

Functional XML (and HTML, SVG, ..) generation

PXML intends to be a simple, Perl based representation for XML, or at least the subset that's necessary for doing most tasks. Currently it doesn't support XML namespaces properly (manually prefixing element names may be a workable solution, though?). It is primarily meant to produce XML output; parsing of XML is of secondary interest (but Htmlgen already has some code to parse by way of HTML::TreeBuilder).

Its in-memory representation are PXML::Element (or subclassed) objects. Serialization is done using functions/procedures from PXML::Serialize (also, using PXML::Preserialize if necessary for performance).

The body of elements can be a mix of standard Perl arrays, FP::PureArrays, linked lists based on FP::List, and promises (FP::Lazy, FP::Stream), the latter of which allow for the generation of streaming output (which means the document is generated while it is being serialized, thus there's no memory needed to hold the whole document at once).

Direct creation of XML elements:

use PXML::Element;
my $element= PXML::Element->new
      ("a", {href=> ""}, ["my server"]);

Using 'tag functions' for shorter code:

my $element= A({href=> ""}, "my server");

See test and testlazy for complete examples, and examples/csv_to_xml for a simple real example, and htmlgen/gen for the program that generates this website. FP::DBI is supposed to fit well with PXML.

Module list

PXML, PXML::XHTML, PXML::HTML5, PXML::SVG, PXML::Tags, PXML::Serialize, PXML::Preserialize, PXML::Util

Comparison with

When generating HTML, CGI's tag functions seem similar, what are the differences?


Perhaps PXML should be renamed to FXML. The idea behind PXML was originally to provide something similar to SXML, using Perl arrays and hashes (hence 'P' instead of 'S'), but that has proven to be pretty impractical, wrapper functions producing blessed objects is a much better user interface.