NAME
Text::FakeXML - Creating text with <things>.
VERSION
Version 0.02
SYNOPSIS
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"
);
METHODS
new
Constructor. Takes an optional series of key/value pairs:
- fh
-
The file handle where to write the output to. If not specified, the currently selected file handle is used.
- version
-
If specified, a leading
<?xml version=...?>
is emitted. - indent
-
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. - level
-
The starting level of indentation. Defaults to zero.
Example:
my
$o
= Text::FakeXML::new
version
=>
'1.0'
;
xml_elt_open
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.
xml_elt_close
Closes the current element. First (and only) argument is the name of the element.
xml_elt
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'
/>
xml_comment
Outputs a comment. Arguments contain the comment text.
AUTHOR
Johan Vromans, <jv at cpan.org>
BUGS
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.
SUPPORT
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
CPAN Ratings
Search CPAN
COPYRIGHT & LICENSE
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.