XML::W...:Simple(3pm)
π XML::Writer::Simple π
okay bestie, welcome to XML::Writer::Simple β it lives in the User Contributed Perl Documentation corner of the manual-verse (that's the 3pm situation) and it's literally here to make XML generation not a whole ordeal. β¨
πΈ NAME πΈ
XML::Writer::Simple β Create XML files easily! π¦
π SYNOPSIS π
use XML::Writer::Simple dtd => "file.dtd";
print xml_header(encoding => 'iso-8859-1');
print para("foo",b("bar"),"zbr");
# if you want CGI but you do not want CGI :)
use XML::Writer::Simple ':html';
π USAGE π
So the whole vibe here: this module borrowed some ideas from CGI to make life easier for anyone who needs to generate XML code. You can use it in three flavours (or mix and match them, you do you):
π·οΈ tags
When you import the module you can just say which tags you're gonna be using:
use XML::Writer::Simple tags => [qw/p b i tt/];
print p("Hey, ",b("you"),"! ", i("Yes ", b("you")));
and that generates
<p>Hey <b>you</b>! <i>Yes <b>you</b></i></p>
ate. π
π dtd
You can supply a DTD β it'll get analyzed, and then the tags get used:
use XML::Writer::Simple dtd => "tmx.dtd";
print tu(seg("foo"),seg("bar"));
π xml
You can supply an XML file (or a reference to a list of XML files). They'll get parsed, and the tags get used:
use XML::Writer::Simple xml => "foo.xml";
print foo("bar");
π§© partial
You can supply a 'partial' key to generate prototypes for partial tag construction. Like, for instance:
use XML::Writer::Simple tags => qw/foo bar/, partial => 1;
print start_foo;
print ...
print end_foo;
You can also use tagsets, where whole sets of tags from a well known format get imported. For example, to use HTML:
use XML::Writer::Simple ':html';
β¨ EXPORT β¨
This module exports one function for each element in the dtd or xml file you're using. Details down below, bestie. π«Ά
π₯ FUNCTIONS π₯
import
Used when you use the module β don't call it directly, okay? π
xml_header
This function returns the xml header string, without encoding definition, with a trailing new line. Default XML encoding should be UTF-8, by the way. π
You can force an encoding by passing it as an argument:
print xml_header(encoding=>'iso-8859-1');
powertag
Used to specify a powertag. For instance:
powertag("ul","li");
ul_li([qw/foo bar zbr ugh/]);
will generate
<ul>
<li>foo</li>
<li>bar</li>
<li>zbr</li>
<li>ugh</li>
</ul>
You can also supply this information when loading the module, with
use XML::Writer::Simple powertags=>["ul_li","ol_li"];
Powertags support three level tags as well:
use XML::Writer::Simple powertags=>["table_tr_td"];
print table_tr_td(['a','b','c'],['d','e','f']);
quote_entities
To use the special characters "<", ">" and "&" on your PCDATA content you need to protect them. You can either do that yourself or call this function.
print f(quote_entities("a < b"));
π fr fr, those three characters will absolutely wreck your PCDATA if you don't handle them. Protect them or call quote_entities β your call, just don't say nobody warned you.
π AUTHOR π
Alberto SimΓ΅es, "<ambs@cpan.org>"
π BUGS π
Please report any bugs or feature requests to "bug-xml-writer-simple@rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-Writer-Simple>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. π
π COPYRIGHT AND LICENSE π
Copyright 1999-2012 Project Natura.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page bestie π this manual page came to you from perl v5.34.0 and it's dated 2022-06-28 β iconic, honestly. go generate some XML and slay. periodt. π
β¨
π¦ where this page comes from
- debian bookworm: libxml-writer-simple-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libxml-writer-simple-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libxml-writer-simple-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libxml-writer-simple-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libxml-writer-simple-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms