[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] Returning XML output for AJAX


Bruce McKenzie wrote:
OK, so I'm way behind the rest of the world when it comes to XML -- but I am using CGI::Application -- so how hard could it be to catch up? :-)

What I want to do is return XML (as an Ajax response) to the jQuery Interface library Autocomplete plugin.

In the plugin documentation example, data is provided by an .asp document that looks like this:

<?xml version="1.0"?>
<ajaxresponse>
   <item>
     <text><![CDATA[text to display]]></text>
     <value><![CDATA[value to fill]]></value>
   </item>
</ajaxresponse>

Of the modules on CPAN that could produce this XML structure, which would be *easiest* to use? Do I need to change the headers of the CGI::Application response?

IMHO, that would be XML::Simple. It's a bit tricky to force XML::Simple to generate the exact same output, but it depends a lot on the context if you need it.

Here's some sample code to demonstrate:

#!/usr/bin/perl

use XML::Simple;

my $item = {
    text  => 'text to display',
    value => 'value to fill',
};

print XMLout( { ajaxresponse => { item => $item } }, noattr => 1, keeproot => 1, xmldecl => 1 );

__END__
<?xml version='1.0' standalone='yes'?>
<ajaxresponse>
  <item>
    <text>text to display</text>
    <value>value to fill</value>
  </item>
</ajaxresponse>


For bigger XML snippets where I need a very specific layout, I tend to use HTML::Template templates instead. But most of the time, XML::Simple manages to do the job just fine.

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.