[Catalyst] Can Catalyst-Plugin-AtomServer support nontext/xhtml content?

John Napiorkowski jjn1056 at yahoo.com
Mon Sep 25 18:53:06 CEST 2006


--- Jonathan Rockway <jon at jrock.us> wrote:

> XML::Atom is for Atom ("RSS") feeds.  If you have
> non-Atom tags in your
> XML, I think the feed server assumes it's some
> variant of XHTML instead.
>  What is the xmlns on the <div> tags?
> 
> Here's how you're "supposed" to use
> C::P::AtomServer:
> 
>
http://search.cpan.org/~btrott/Catalyst-Plugin-AtomServer-0.04/lib/Catalyst/Plugin/AtomServer.pm#EXAMPLE
> 
> Also, Atom's mime type is application/atom+xml (not
> the others you
> tried), so that might mean something.
> 
> But if your XML isn't Atom, I'm not sure why you're
> using
> C::P::AtomServer.  More information about what
> you're trying to achieve
> would be appreciated.  I see no problem with:
> 
> sub serve_xml : ... {
>    my ($self, $c, @args) = @_;
>    $c->response->content_type('application/xml')
>    $c->response->body( XMLOut( [hash to xml encode]
> );
> }
> 
> if all you want to do is spew some XML to the
> client.
> 
> Regards,
> Jonathan Rockway
> 
> John Napiorkowski wrote:
> > Hi,
> > 
> > I'm using the Catalyst-Plugin-AtomServer as a way
> to
> > expose some xml encoded data but having trouble
> > getting the plugin to accept a content type of
> 'xml'. 
> > I can do:
> > 
> > use XML::Simple;
> > my $content = XML::Atom::Content;
> > 
> > $content->type('application/xml')
> > $content->body( XMLOut( [hash to xml encode] );
> > 
> > and then add the content object to the entry
> object
> > but I still get output that wraps the XML in an
> xhtml
> > div tag.  The content type attribute does get set
> > correctly though and I do get the xml content
> inside
> > the content tags, just it has the extra div tag
> which
> > messes up my clients on the other side.  I've
> tried
> > 'application/xml', 'xml', 'text/xml', etc. but
> none of
> > these seem to work.
> > 
> > Has anyone gotten this to work with this plugin or
> > found a different way to accomplsih this task? 
> Advice
> > appreciate

My project goal is to build a set of REST inspired web
services that use ATOM as a wrapper, similar to what
Google is doing with it's Data API
(http://code.google.com/apis/gdata/index.html). 
Perhaps I don't fully understand how this works, but
my current understanding is that ATOM allows you to
specify xml inside the content tags as long as you set
a type attribute of something with 'xml' in it, like
"application/xml" for example.

There are a lot of different ways to build this kind
of service.  We could have choosen something like the
XOXO format for our list oriented data, for example,
or to just use XML::Dumper on the stash/request body. 
I felt there were security concerns with this, but
with the correct checking I suppose that wouldn't
really be a problem.

I'd be happy to give additional details about my
project, but what I am trying to figure out is if the
XML::Atom plugin is going to support what I need to do
without having to modify it in some way.  Based on my
review of the code it seems like unless you set the
content body to something that looks like text
XML::Atom will automatically assume it xhtml and wrap
your content body in a <div> tag.  Here's what it
looks like when I create it in XML::Atom(this is a
test example):


## Create an XML::Atom Entry object, etc.
my $content = XML::Atom::Content;

$content->type('application/xml');

$content->body(q[
  <member xmlns="http://mysite.com/ns#member">
    <name>blah blah</name>
    <title>nobody</title>
  </member>
]);

and what I see in the browser after passing this
through the XML::Atom::View module:

<content
  xmlns="http://www.w3.org/2005/Atom"
  xmlns:default="http://www.w3.org/1999/xhtml"
  type="application/xml">
  <div xmlns="http://www.w3.org/1999/xhtml">
    <member xmlns="http://mysite.com/ns#member" >
      <name>blah blah</name>
      <title>nobody</title>
    </member>
  </div>
</content>


Now the atom spec says I can do XML content and have
it look like (same example as above):

<content type="application/xml">
  <member xmlns="http://mysite.com/ns#member" >
    <name>blah blah</name>
    <title>nobody</title>
  </member>
</content>

However nothing I do seems to get the XML::Atom plugin
to work this way.  Now, I realize this is not a
tradional use for this kind of feed, but the
specification seems to indicate it's a valid one.

Another approach I could take is how Google is doing
this by adding a new namespace and placing the data
elements inside the entry tag and not the content tag.
 Maybe this is a better way?  This would look (very
roughly like)

<entry member:xmlsn="http://mysite.com/ns#member">
    <member:name>blah blah</name>
    <member:title>nobody</title>
</entry>

It just seems neater to me to place all my stuff
inside the content tag, that way I can easily parse it
by sending the return to entry->content->body to
XML::Simple or some other xml parser.

Anyway, if anyone has gotten this plugin to perform in
this way I'd appreciate hearing about it.

Thanks,
John

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Catalyst mailing list