NAME
Froody::Response::XML - create a response from a XML::LibXML document
SYNOPSIS
my $response = Froody::Response::XML->new()
->structure($froody_method)
->xml($xml_doc);
print $response->render;
DESCRIPTION
This is a concrete implementation of Froody::Response. It takes its input from an XML::LibXML::Document.
use XML::LibXML;
my $xml_doc = XML::LibXML::Document->new( "1.0", "utf-8" );
# create the rsp
my $rsp = $xml_doc->createElement("rsp");
$rsp->setAttribute("stat", "ok");
$xml_doc->setDocumentElement($rsp);
# add the child node foo
my $foo = $xml_doc->createElement("foo");
$foo->appendText("bar"); # note, must pass bytes in the above encoding
$rsp->appendChild($foo);
my $rsp = Froody::Response::XML->new()
->structure($froody_method)
->xml($xml_doc);
You can get and set the current XML document by usinc xml
. We only hold a reference to the data so you can modify the XML after you've assigned it to the response and it'll still effect that response. This means the above could be re-ordered as:
use XML::LibXML;
my $xml_doc = XML::LibXML::Document->new( "1.0", "utf-8" );
my $rsp = Froody::Response::XML->new()
->structure($froody_method)
->xml($xml_doc);
# create the rsp
my $rsp = $xml_doc->createElement("rsp");
$rsp->setAttribute("stat", "ok");
$xml_doc->setDocumentElement($rsp);
# add the child node foo
my $foo = $xml_doc->createElement("foo");
$foo->appendText("bar"); # note, must pass bytes in the above encoding
$rsp->appendChild($foo);
And it'll work just as fine. This does however mean you should be careful about re-using XML::LibXML objects between responses.
Converting other Responses to Froody::Response::XML objects
Once you've loaded this class you can automatically convert other Froody::Response class instances to Froody::Response::XML objects with the as_xml
method.
use Froody::Response::String;
use Froody::Response::XML;
my $string = Froody::Response::String
->new()
->structure($froody_method)
->set_bytes($bytes);
->as_xml;
print ref($string); # prints "Froody::Response::XML"
BUGS
None known.
Please report any bugs you find via the CPAN RT system. http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Froody
AUTHOR
Copyright Fotango 2005. All rights reserved.
Please see the main Froody documentation for details of who has worked on this project.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.