Mojolicious::Plugin::JsonToXml - JSON to XML Mojolicious Plugin
# Mojolicious
$self->plugin('json_to_xml');
# Mojolicious::Lite
plugin 'json_to_xml';
# or
plugin 'json_to_xml', { status => 200 }; # JSON to XML only 200 status code
# or
plugin 'json_to_xml', {
exclude => [ qr{/no\.xml}, '/no2.xml' ] # Exclude urls
};
Simple:
get '/test.json' => sub { shift->render_json({ response => 'ok' }) };
# /test.json : {"response": "ok"}
# /test.xml :
<?xml version="1.0" encoding="UTF-8"?>
<response>ok</response>
List:
get '/list.json' => sub { shift->render_json([1, 2, 3]) };
# /list.json : [1,2,3]
# /list.xml :
<?xml version="1.0" encoding="UTF-8"?>
<list><item>1</item><item>2</item><item>3</item></list>
Tags:
get '/tags.json' => sub { shift->render_json({
tests => [
{ id => 1, title => 'JSON & XML', __node => 'test' },
{ id => 2, title => 'JSON > XML', },
]
}) };
# /tags.json : {"tests":[{"id":1},{"id":2}]}
# /tags.xml :
<?xml version="1.0" encoding="UTF-8"?>
<tests>
<test><id>1</id><title>JSON & XML</title></test>
<test><id>2</id><title>JSON > XML</title></test>
</tests>
Mojolicous::Plugin::JsonToXml is a plugin to easily use XML format if exists JSON format. Automatiс render JSON to XML data
Mojolicious::Plugin::JsonToXml inherits all methods from Mojolicious::Plugin and implements the following new ones.
$plugin->register;
Register plugin hooks in Mojolicious application.
my $xml = $plugin->json2xml( $json );
Simple render json to xml.
If $json is missing or empty, xml contains root tag <empty />.
Each element of array is <item> ... </item>.
Mojolicious, Mojolicious::Guides, http://mojolicious.org.
Anatoly Sharifulin <[email protected]>
Please report any bugs or feature requests to bug-mojolicious-plugin-jsontoxml at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.htMail?Queue=Mojolicious-Plugin-JsonToXml. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.
Github
http://github.com/sharifulin/Mojolicious-Plugin-JsonToXml/tree/master
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.htMail?Dist=Mojolicious-Plugin-JsonToXml
AnnoCPAN: Annotated CPAN documentation
CPANTS: CPAN Testing Service
http://cpants.perl.org/dist/overview/Mojolicious-Plugin-JsonToXml
CPAN Ratings
Search CPAN
Copyright (C) 2010 by Anatoly Sharifulin.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Hey! The above document had some coding errors, which are explained below:
- Around line 60:
-
Non-ASCII character seen before =encoding in 'Automatiс'. Assuming UTF-8