XML-Generator
view release on metacpan or search on metacpan
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:
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
"version" : "1.13"
},
"XML::Generator::DOM" : {
"file" : "lib/XML/Generator/DOM.pm",
"version" : "1.13"
},
"XML::Generator::DOM::util" : {
"file" : "lib/XML/Generator/DOM.pm",
"version" : "1.13"
},
"XML::Generator::cdata" : {
"file" : "lib/XML/Generator.pm",
"version" : "1.13"
},
"XML::Generator::comment" : {
"file" : "lib/XML/Generator.pm",
"version" : "1.13"
},
"XML::Generator::final" : {
"file" : "lib/XML/Generator.pm",
"version" : "1.13"
provides:
XML::Generator:
file: lib/XML/Generator.pm
version: '1.13'
XML::Generator::DOM:
file: lib/XML/Generator/DOM.pm
version: '1.13'
XML::Generator::DOM::util:
file: lib/XML/Generator/DOM.pm
version: '1.13'
XML::Generator::cdata:
file: lib/XML/Generator.pm
version: '1.13'
XML::Generator::comment:
file: lib/XML/Generator.pm
version: '1.13'
XML::Generator::final:
file: lib/XML/Generator.pm
version: '1.13'
XML::Generator::overload:
file: lib/XML/Generator.pm
my $gen = XML::Generator->new(pretty => "\t");
Pretty printing does not apply to CDATA sections or Processing
Instructions.
conformance
If the value of this option is 'strict', a number of syntactic checks
are performed to ensure that generated XML conforms to the formal XML
specification. In addition, since entity names beginning with 'xml' are
reserved by the W3C, inclusion of this option enables several special
tag names: xmlpi, xmlcmnt, xmldecl, xmldtd, xmlcdata, and xml to allow
generation of processing instructions, comments, XML declarations,
DTD's, character data sections and "final" XML documents, respectively.
Invalid characters (http://www.w3.org/TR/xml11/#charsets) will be
filtered out. To disable this behavior, supply the
'filter_invalid_chars' option with the value 0.
See "XML CONFORMANCE" and "SPECIAL TAGS" for more information.
filterInvalidChars, filter_invalid_chars
This would produce the following declaration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
Assuming that $xhtml_w3c and $xhtml_dtd had the correct values.
Note that you can also specify a DTD on creation using the new()
method's dtd option.
xmlcdata
Character data section; arguments are concatenated and placed inside
<![CDATA[ ... ]]> character data section delimiters. Any occurences of
']]>' in the concatenated arguments are converted to ']]>'.
xml
"Final" XML document. Must be called with one and exactly one
XML::Generator-produced XML document. Any combination of
XML::Generator-produced XML comments or processing instructions may also
be supplied as arguments. Prepends an XML declaration, and re-blesses
the argument into a "final" class that can't be embedded.
stopword = apos
stopword = atributes
stopword = declartion
stopword = desireable
stopword = doctype
stopword = dtd
stopword = eg
stopword = filterInvalidChars
stopword = qualifiedAttributes
stopword = xml
stopword = xmlcdata
stopword = xmlcmnt
stopword = xmldecl
stopword = xmldtd
stopword = xmlns
stopword = xmlpi
stopword = prolog
[CopyFilesFromBuild::Filtered]
copy = cpanfile
copy = Makefile.PL
lib/XML/Generator.pm view on Meta::CPAN
my $gen = XML::Generator->new(pretty => "\t");
Pretty printing does not apply to CDATA sections or Processing Instructions.
=head2 conformance
If the value of this option is 'strict', a number of syntactic
checks are performed to ensure that generated XML conforms to the
formal XML specification. In addition, since entity names beginning
with 'xml' are reserved by the W3C, inclusion of this option enables
several special tag names: xmlpi, xmlcmnt, xmldecl, xmldtd, xmlcdata,
and xml to allow generation of processing instructions, comments, XML
declarations, DTD's, character data sections and "final" XML documents,
respectively.
Invalid characters (http://www.w3.org/TR/xml11/#charsets) will be filtered
out. To disable this behavior, supply the 'filter_invalid_chars' option with
the value 0.
See L<"XML CONFORMANCE"> and L<"SPECIAL TAGS"> for more information.
lib/XML/Generator.pm view on Meta::CPAN
sub xmldtd {
my $this = shift;
my $dtd = shift || return undef;
# return the appropriate <!DOCTYPE> thingy
$dtd ? return(qq{<!DOCTYPE } . (join ' ', @{$dtd}) . q{>})
: return('');
}
=head2 xmlcdata
Character data section; arguments are concatenated and placed inside
<![CDATA[ ... ]]> character data section delimiters. Any occurences of
']]>' in the concatenated arguments are converted to ']]>'.
=cut
sub xmlcdata {
my $this = shift;
$this->XML::Generator::util::tag('xmlcdata', @_)
unless $this->{conformance} eq 'strict';
my $xml = join '', @_;
# ]]> is not allowed; change it to ]]>
$xml =~ s/]]>/]]>/g;
XML::Generator::util::filter($xml);
$xml = "<![CDATA[$xml]]>";
return XML::Generator::cdata->new([$xml]);
}
=head2 xml
"Final" XML document. Must be called with one and exactly one
XML::Generator-produced XML document. Any combination of
XML::Generator-produced XML comments or processing instructions may
also be supplied as arguments. Prepends an XML declaration, and
re-blesses the argument into a "final" class that can't be embedded.
lib/XML/Generator.pm view on Meta::CPAN
if (@args || $empty eq 'close') {
if ($empty eq 'args' && @args == 1 && ! defined $args[0]) {
@xml = ($xml .= ' />');
} else {
$xml .= '>';
if ($indent) {
my $prettyend = '';
foreach my $arg (@args) {
next unless defined $arg;
if ( UNIVERSAL::isa($arg, 'XML::Generator::cdata' ) ) {
my $copy = $xml;
push @xml, $copy, $arg;
$xml = '';
} else {
if ( UNIVERSAL::isa($arg, 'XML::Generator::overload') &&
! UNIVERSAL::isa($arg, 'XML::Generator::pi') ) {
$xml .= "\n$indent";
$prettyend = "\n";
XML::Generator::util::_fixupNS($namespace, $arg) if ref $arg->[0];
my @cdata;
for my $i (0..$#$arg) {
if (UNIVERSAL::isa($arg->[$i], 'XML::Generator::cdata')) {
push @cdata, $arg->[$i];
$arg->[$i] = "\001";
}
}
$arg =~ s/\n/\n$indent/gs;
if (@cdata) {
my @pieces = split "\001", $arg;
my $copy = $xml;
push @xml, $copy;
$xml = '';
$arg = '';
for my $i (0..$#pieces) {
if (defined $cdata[$i]) {
push @xml, $pieces[$i], $cdata[$i];
} else {
push @xml, $pieces[$i];
}
}
}
}
$xml .= "$arg";
}
}
$xml .= $prettyend;
push @xml, ($xml, "</$prefix$tag>");
} else {
@xml = $xml;
foreach my $arg (grep defined, @args) {
if ( UNIVERSAL::isa($arg, 'XML::Generator::overload') &&
(! ( UNIVERSAL::isa($arg, 'XML::Generator::cdata' ) ||
UNIVERSAL::isa($arg, 'XML::Generator::pi' )))) {
XML::Generator::util::_fixupNS($namespace, $arg) if ref $arg->[0];
}
push @xml, $arg;
}
push @xml, "</$prefix$tag>";
}
}
} elsif ($empty eq 'ignore') {
@xml = ($xml .= '>');
lib/XML/Generator.pm view on Meta::CPAN
use base 'XML::Generator::overload';
package XML::Generator::comment;
use base 'XML::Generator::overload';
package XML::Generator::pi;
use base 'XML::Generator::overload';
package XML::Generator::cdata;
use base 'XML::Generator::overload';
1;
__END__
=head1 AUTHORS
=over 4
lib/XML/Generator/DOM.pm view on Meta::CPAN
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
ok(UNIVERSAL::isa($@, 'XML::DOM::DOMException'));
$xml = $x->foo(['bar'], {'baz:foo' => 'qux', 'fob' => 'gux'});
ok($xml->toString eq '<bar:foo baz:foo="qux" bar:fob="gux"/>' ||
$xml->toString eq '<bar:foo bar:fob="gux" baz:foo="qux"/>');
$x = new XML::Generator::DOM 'dtd' => [ 'foo', 'SYSTEM', '"http://foo.com/foo"' ];
$xml = $x->xmldecl();
ok($xml->getStandalone, 'no');
$xml = $x->xmlcdata("test");
ok(UNIVERSAL::isa($xml, 'XML::DOM::CDATASection'));
ok($xml->getData, 'test');
$x = new XML::Generator::DOM;
$xml = $x->foo($x->xmlcdata("bar"), $x->xmlpi("baz", "bam"));
ok($xml->toString, '<foo><![CDATA[bar]]><?baz bam?></foo>');
$xml = $x->foo(42);
$xml = $x->xml($xml);
ok($xml->toString,
'<?xml version="1.0" standalone="yes"?>
<foo>42</foo>
');
eval {
t/Generator.t view on Meta::CPAN
ok($xml, '<xml />');
$x = new XML::Generator 'conformance' => 'strict',
'dtd' => [ 'foo', 'SYSTEM', '"http://foo.com/foo"' ];
$xml = $x->xmldecl();
ok($xml,
'<?xml version="1.0" standalone="no"?>
<!DOCTYPE foo SYSTEM "http://foo.com/foo">
');
$xml = $x->xmlcdata("test");
ok($xml, '<![CDATA[test]]>');
$x = new XML::Generator 'pretty' => 2, 'conformance' => 'strict';
$xml = $x->foo($x->bar());
ok($xml,
'<foo>
<bar />
</foo>');
$xml = $x->foo($x->xmlcdata("bar"), $x->xmlpi("baz"));
ok($xml, '<foo><![CDATA[bar]]><?baz?></foo>');
# test that cdata is not intended when pretty printing is on
$xml = $x->foo($x->bam($x->xmlcdata("bar\nbar")));
ok($xml, '<foo>
<bam><![CDATA[bar
bar]]></bam>
</foo>');
$x = new XML::Generator 'conformance' => 'strict';
$xml = $x->foo(42);
$xml = $x->xml($xml);
ok($xml,
'<?xml version="1.0"?>
t/author-pod-spell.t view on Meta::CPAN
declartion
desireable
doctype
dtd
eg
filterInvalidChars
lib
prolog
qualifiedAttributes
xml
xmlcdata
xmlcmnt
xmldecl
xmldtd
xmlns
xmlpi
( run in 0.802 second using v1.01-cache-2.11-cpan-454fe037f31 )