Text::FakeXML - Creating text with <things>.
Version 0.02
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.
<?xml version=...?>
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.
Example:
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.
Johan Vromans, <jv at cpan.org>
<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.
bug-text-fakexml at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Text::FakeXML
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-FakeXML
CPAN Ratings
http://cpanratings.perl.org/d/Text-FakeXML
Search CPAN
http://search.cpan.org/dist/Text-FakeXML
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.
To install Text::FakeXML, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::FakeXML
CPAN shell
perl -MCPAN -e shell install Text::FakeXML
For more information on module installation, please visit the detailed CPAN module installation guide.