Text::FakeXML - Creating text with <things>.
Many applications use XML-style data, e.g., for configuration. However, very often this data is not 'real' XML, but just text with some XML-like markups. Therefore is it not necessary to pull in the whole vast XML machinery to create these files. A simple 'fake' module is sufficient.
For example, consider this real-life config file for eye-of-gnome:
<?xml version='1.0'?> <gconf> <entry name='geometry_collection' mtime='1164190071' type='string'> <stringvalue>440x350+1063+144</stringvalue> </entry> </gconf>
This doesn't require anything fancy:
use Text::FakeXML; my $cfg = Text::FakeXML->new(version => "1.0"); $cfg->xml_elt_open("gconf"); $cfg->xml_elt("entry", name => "geometry_collection", mtime => "1164190071", type => "string"); $cfg->xml_elt("stringvalue", "440x350+1063+144" ); $cfg->xml_elt_close("gconf");
Constructor. Takes an optional series of key/value pairs:
The file handle where to write the output to. If not specified, the currently selected file handle is used.
If specified, a leading
<?xml version=...?> is emitted.
Indentation for each level of tags. Must be a string (e.g., two spaces
" ") or a number that indicates the desired number of spaces. Default is two spaces.
The starting level of indentation. Defaults to zero.
my $o = Text::FakeXML::new version => '1.0';
Emits the opening tag for a new element. First argument is the name of the element. It may be followed by a series of key/value pairs that will be used as attributes for this element.
Closes the current element. First (and only) argument is the name of the element.
Outputs a simple element. First argument is the name of the element, the second argument (if present) is the value. This may be followed by a series of key/value pairs that will be used as attributes for this element.
$o->xml_elt("foo") -> <foo /> $o->xml_elt("foo", "bar") -> <foo>bar</foo> $o->xml_elt("foo", "bar", id => 1) -> <foo id='1'>bar</foo> $o->xml_elt("foo", undef, id => 1) -> <foo id='1' />
Outputs a comment. Arguments contain the comment text.
<jv at cpan.org>
Please report any bugs or feature requests to
bug-text-fakexml at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-FakeXML. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
You can also look for information at:
Copyright 2008 Johan Vromans, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.