XML-Generator-1.04/ 0000755 0001756 0001001 00000000000 11610033234 013564 5 ustar Ben Holzman None XML-Generator-1.04/Changes 0000644 0001756 0001001 00000015230 11610032134 015056 0 ustar Ben Holzman None Revision history for Perl extension XML::Generator.
1.04 Fri Jul 15 08:35:00 2011
- Added the filter_invalid_chars option, which is turned on by default
under strict mode.
1.03 Thu Jul 30 17:02:00 2009
- Version bump because somebody released an unauthorized
XML-Generator-1.02
1.01 Tue Jul 8 11:45:00 2007
- Documentation cleanup.
1.0 Fri Jun 22 16:51:00 2007
- Fixed bug #23594, "Embedded escaping does not work as expected",
reported by M. Zizka; clarified documentation and added 'even-entities'
argument to 'escape' parameter.
- As part of above fix, supplying an unexpected true argument to 'escape'
parameter results in warning.
- Fixed bug #18609, "cdata also pretty-printed", reported by Daniel Schroeer.
- Fixed bug #18656, reported by Peter (Stig) Edwards; just removed single
quotes around Tie::IxHash in require line.
0.99_02 Tue Oct 19 23:02:00 2004
- Fixed mistake in RDF example.
0.99_01 Tue Oct 19 22:58:00 2004
- Changed default behavior of 'use XML::Generator' to not attempt to export
AUTOLOAD. Removed ':noimport' option.
- Allowed more than two components in a namespace, to allow explicit xmlns:
attributes to be output on demand. Introduced '#default' token.
- Improved output aesthetics when there are lot of attributes and the generator
was configured with the 'pretty' option.
- Added allowedXMLTags (alias to allowed_xml_tags) and qualified_attributes
(alias to qualifiedAttributes) to rationalize interface.
0.99 Tue Mar 23 11:17:00 2004
- Removed automatic prefixing of attribute names when using a namespace.
- Added 'qualifiedAttributes' constructor option to emulate prior attribute
prefixing behavior.
- Always syntax check attribute names under strict conformance.
- Add documentation on using Tie::IxHash to get predictable attribute ordering.
- Allow tag 'AUTOLOAD'.
- Fixed bug with default namespace.
- More tests
0.98 Mon Mar 1 18:26:00 2004
- Fixed bug in DOM.t when XML::DOM not installed (caused by fix in 0.97)
0.97 Mon Mar 1 15:22:00 2004
- Fixed bugs in DOM.t reported by David Wheeler.
0.96 Sun Feb 29 23:00:00 2004
- More documentation fixups.
- Only check for xml() subs under strict conformance.
- Small performance optimizations.
0.95 Sun Feb 29 22:21:00 2004
- Enhanced STACKED AUTOLOAD feature to provide a default import()
- Documentation fixups.
0.94 Sun Feb 29 14:21:00 2004
- FIXED IMPLEMENTATION OF NAMESPACES!! XML::Generator is now conformant.
Note that the semantics of namespaces have changed!
- Implemented AUTOLOAD exporting to simplify syntax.
- Implement STACKED AUTOLOADs to simplify sub-classing.
- Added "macro" options ':standard', ':std', ':strict' and ':pretty'.
- Added new 'allowed_xml_tags' option to allow tags starting with 'xml'
under strict conformance.
- Documented the 'version', 'encoding' and 'dtd' options.
- Added arguments to xmldecl() to allow more control.
- Changed XML comment behavior when escaping '--' to escape both dashes.
- Fixed memory leak in constructor. Bug #4513.
- Fixed bug in t/DOM.t that caused it to fail when DOM.pm was installed. Bug #3220.
0.93 Wed Jan 22 10:41:00 2003
- Added 'high-bit' option to escape to allow escaping of upper ASCII.
- Fixed a test bug that assumed the order of elements in a hash.
0.92 Tue Jan 21 13:12:00 2003
- Finally (after multiple bug reports) stopped requiring that XML::DOM be
installed for the tests to pass. Sorry this took so long to get fixed.
- Also fixed a bug in XML::Generator::DOM's POD that made it look strange
on search.cpan.org (reported by Ken Williams).
0.91 Mon Dec 11 11:33:32 2000
- Added XML::Generator::DOM subclass for producing DOM trees instead of
strings.
- New choices for the 'empty' option: 'compact' and 'args'.
- Changed the semantics of 'pretty' option; CDATA sections and Processing
Instructions are no longer subject to the pretty printing rules. Thanks
for the bug report from Murat Uenalan.
- Using closures for tag generation, which seems to save a little bit of
time. Might not be worth it in the long run, for maintainability's sake.
- Fix for perl versions that can't use 'for' as a statement modifier (pre 5.005)
courtesy of Neil Prockter (n.prockter@lse.ac.uk).
- Some documentation fixups.
0.9 Sat Nov 18 11:13:24 2000
- Massive code reorganization to support subclassing, courtesy of
Nathan Winger (nate@nateware.com)
- New instantiation option, 'empty', to control how empty tags are
rendered.
- Improved internal representation for improved performance
( $gen->foo($gen->bar($gen->baz( $really_big_string ))) used to copy
$really_big_string three times; as long as the 'pretty' option is not
supplied, this is no longer the case. )
- Fixed xml() tag to allow comments and processing instructions before
and/or after the xml document.
- New special tag, xmldtd(), which used to be part of xmldecl().
0.8 Wed Jul 12 17:10:12 2000
- Bug-fix for pretty-printing
- New special tag, "xml" which takes a complete XML document and
"finalizes" it, so it can't be further embedded.
- Arguments passed as scalar refs will not be escaped, even if the
XML::Generator object was constructed with the 'escape' => "always"
option.
0.7 Mon Jun 13 09:14:32 2000
- Pretty-printing patch from Bron Gondwana
- Undefined warnings patch from Bron Gondwana
0.6 Sun Jun 11 16:02:00 2000
- Cleaned-up, modularized rewrite courtesy of Bron Gondwana
(perlcode@brong.net)
- XML::Generator now returns objects blessed into XML::Generator::auto
which contains only an AUTOLOAD that redirects requests to the
proper method in XML::Generator.
- A new option is available in the constructor to force stricter
conformance to the XML specification ('conformance' => 'strict').
This also enables some special tags; "xmlpi", "xmlcmnt", "xmldecl"
and "xmlcdata" that can be used to generate, respectively, processing
instructions, comments, the XML declaration, and character data
sections.
0.5 Thu Sep 08 11:12:04 1999
- Fixed one lingering definedness bug
- Added escaping options to XMLify content
- Added global namespace option
- Fixed namespace support somewhat
0.4 Fri Jul 02 11:44:32 1999
- Fixed a few remarkably dumb bugs which I can't believe survived
this long. Improved the documentation slightly.
0.3 Tue Apr 13 09:11:13 1999
- Fixed undefined variables warnings as reported by John Labovitz
(johnl@meer.net)
0.2 Wed Feb 10 12:00:00 1999
- Added support for namespaces; bholzman
- Allowed "new" as a tag name; bholzman
0.1 Wed Nov 11 20:39:11 1998
- first public version; bholzman
0.01 Wed Nov 11 20:17:39 1998
- original version; created by h2xs 1.18
XML-Generator-1.04/DOM.pm 0000444 0001756 0001001 00000013333 10030055071 014540 0 ustar Ben Holzman None package XML::Generator::DOM;
=head1 NAME
XML::Generator::DOM - XML::Generator subclass for producing DOM trees instead of strings.
=head1 SYNOPSIS
use XML::Generator::DOM;
my $dg = XML::Generator::DOM->new();
my $doc = $dg->xml($dg->xmlcmnt("Test document."),
$dg->foo({'baz' => 'bam'}, 42));
print $doc->toString;
yields:
42
=head1 DESCRIPTION
XML::Generator::DOM subclasses XML::Generator in order to produce DOM
trees instead of strings (see L and L). This
module is still experimental and its semantics might change.
Essentially, tag methods return XML::DOM::DocumentFragment objects,
constructed either from a DOM document passed into the constructor or
a default document that XML::Generator::DOM will automatically construct.
Calling the xml() method will return this automatically constructed
document and cause a fresh one to be constructed for future tag method
calls. If you passed in your own document, you may not call the xml()
method.
Below, we just note the remaining differences in semantics between
XML::Generator methods and XML::Generator::DOM methods.
=cut
use strict;
use Carp;
use XML::Generator ();
use base 'XML::Generator';
use XML::DOM;
use vars qw( $AUTOLOAD $VERSION );
$VERSION = '0.2';
=head1 CONSTRUCTOR
These configuration options are accepted but have no effect on the
semantics of the returned object: escape, pretty, conformance and
empty.
=head1 TAG METHODS
Subsequently, tag method semantics are somewhat different for
this module compared to XML::Generator. The primary difference is
that tag method return XML::DOM::DocumentFragment objects. Namespace
and attribute processing remains the same, but remaining arguments to
tag methods must either be text or other XML::DOM::DocumentFragment
objects. No escape processing, syntax checking, or output control is
done; this is all left up to XML::DOM.
=cut
sub new {
my $class = shift;
my $dom;
for (my $i = 0; $i < $#_; $i+=2) {
if ($_[$i] eq 'dom_document') {
$dom = $_[$i+1];
unless (UNIVERSAL::isa($dom, 'XML::DOM::Document')) {
croak "argument to 'dom' option not an XML::DOM::Document object";
}
splice @_, $i, 2;
last;
}
}
if (ref $class) {
$AUTOLOAD = 'new';
return $class->AUTOLOAD(@_);
}
my $this = $class->SUPER::new(@_);
$this->{'dom'} = $dom || XML::Generator::DOM::util::new_dom_root();
return $this;
}
=head1 SPECIAL TAGS
All special tags are available by default with XML::Generator::DOM; you don't
need to use 'conformance' => 'strict'.
=head2 xmlpi(@args)
Arguments will simply be concatenated and passed as the data to
the XML::DOM::ProcessingInstruction object that is returned.
=cut
sub xmlpi {
my $this = shift;
my $root = $this->{dom};
my $tgt = shift;
return $root->createProcessingInstruction($tgt, join '', @_);
}
=head2 xmlcmnt
Escaping of '--' is done by XML::DOM::Comment, which replaces both
hyphens with '-'. An XML::DOM::Comment object is returned.
=cut
sub xmlcmnt {
my $this = shift;
my $root = $this->{dom};
my $xml = join '', @_;
return $root->createComment($xml);
}
my $config = 'XML::Generator::util::config';
=head2 xmldecl
Returns an XML::DOM::XMLDecl object. Respects 'version', 'encoding'
and 'dtd' settings in the object.
=cut
sub xmldecl {
my $this = shift;
my $root = $this->{dom};
my $version = $this->$config('version') || '1.0';
my $encoding = $this->$config('encoding') || undef;
my $standalone = $this->xmldtd($this->$config('dtd'))
? "no" : "yes";
return $root->createXMLDecl($version, $encoding, $standalone)
}
=head2 xmldecl
Returns an XML::DOM::DocumentType object.
=cut
sub xmldtd {
my($this, $dtd) = @_;
my $root = $this->{dom};
$dtd ||= $this->$config('dtd');
return unless $dtd && ref($dtd) eq "ARRAY";
return $root->createDocumentType(@{ $dtd });
}
=head2 xmlcdata
Returns an XML::DOM::CDATASection object.
=cut
sub xmlcdata {
my $this = shift;
my $data = join '', @_;
my $root = $this->{dom};
return $root->createCDATASection($data);
}
=head2 xml
As described above, xml() can only be used when dom_document was not
set in the object. The automatically created document will have its XML
Declaration set and the arguments to xml() will be appended to it. Then
a new DOM document is automatically generated and the old one is
returned. This is the only way to get a DOM document from this module.
=cut
sub xml {
my $this = shift;
my $root = $this->{dom};
if ($root != $XML::Generator::DOM::util::root) {
croak "xml() method not allowed when dom_document option specified";
}
$this->{dom} = XML::Generator::DOM::util::new_dom_root();
$root->setXMLDecl($this->xmldecl());
$root->appendChild($_) for @_;
return $root;
}
sub AUTOLOAD {
my $this = shift;
(my $tag = $AUTOLOAD) =~ s/.*:://;;
my $root = $this->{'dom'};
my($namespace, $attr, @args) = $this->XML::Generator::util::parse_args(@_);
$namespace = $namespace->[1] ? $namespace->[1] . ':' : '';
my $xml = $root->createDocumentFragment();
my $node = $xml->appendChild($root->createElement("$namespace$tag"));
if ($attr) {
while (my($k, $v) = each %$attr) {
unless ($k =~ /^[^:]+:/) {
$k = "$namespace$k";
}
$node->setAttribute($k, $v);
}
}
for (@args) {
if (UNIVERSAL::isa($_, 'XML::DOM::Node')) {
$node->appendChild($_);
} else {
$node->appendChild($root->createTextNode($_));
}
}
return $xml;
}
package XML::Generator::DOM::util;
use XML::DOM;
use vars qw($root $parser);
$parser = XML::DOM::Parser->new;
sub new_dom_root {
$root = $parser->parse('<_/>');
$root->removeChild($root->getFirstChild);
return $root;
}
1;
XML-Generator-1.04/Generator.pm 0000644 0001756 0001001 00000132007 11610033152 016052 0 ustar Ben Holzman None package XML::Generator;
use strict;
use Carp;
use vars qw/$VERSION $AUTOLOAD/;
$VERSION = '1.04';
=head1 NAME
XML::Generator - Perl extension for generating XML
=head1 SYNOPSIS
use XML::Generator ':pretty';
print foo(bar({ baz => 3 }, bam()),
bar([ 'qux' => 'http://qux.com/' ],
"Hey there, world"));
# OR
require XML::Generator;
my $X = XML::Generator->new(':pretty');
print $X->foo($X->bar({ baz => 3 }, $X->bam()),
$X->bar([ 'qux' => 'http://qux.com/' ],
"Hey there, world"));
Either of the above yield:
Hey there, world
=head1 DESCRIPTION
In general, once you have an XML::Generator object, you then simply call
methods on that object named for each XML tag you wish to generate.
XML::Generator can also arrange for undefined subroutines in the caller's
package to generate the corresponding XML, by exporting an C
subroutine to your package. Just supply an ':import' argument to
your C