minter has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on a Perl program to bulk-upload information to Google Base. My first attempt is using XML::RSS, since RSS and Atom are supported upload formats. For attributes that can have multiple entries, it seems that the Google Base format wants something like this:
<g:label>Hi-Tech</g:label> <g:label>Business development</g:label> <g:label>Personnel</g:label> <g:label>Silicon Valley</g:label>
However, I can't see how to get XML::RSS to do that. I've tried passing in an array reference, but that just outputs ARRAY(0x####):
$rss->add_item( title => $row->{description}, description => $row->{description}, link => "$urlbase/searchnew.php/$row->{id}", g => { image_link => "$urlbase/$row->{picture}", price => $baseprice, price_type => 'negotiable', id => $row->{id}, label => ['Foo', 'Bar'] } );
outputs
<g:label>ARRAY(0xb10bd0)</g:label> <g:id>4374</g:id> <g:price>$170.00</g:price> <g:price_type>negotiable</g:price_type>
Passing in a list just gives errors about an uneven number of arguments to the hash. And multiple hash keys with the same name, of course, just provides the last one given. So is this sort of thing possible with XML::RSS, or do I need to move to a more specialized XML generator?

Replies are listed 'Best First'.
Re: XML::RSS, Google Base, and multiple entries
by caelifer (Scribe) on Oct 05, 2006 at 21:21 UTC

    My guess would be that, since you are using unknown namespace 'g', XML::RSS does not know how to process its elements. So it does next best thing -- converts them to strings and tries to build hierachy based on the provided datastructure.

    So when you are supplying array reference as in:

    ... -> label => ['Foo', 'Bar'] ...

    In your example it converts array ref to string, and thus "ARRAY(0x#####)" thingy.

    As I read documentation from XML::RSS module, it says that the only supported namespaces out-of-the-box are: Dublin Core (http://purl.org/rss/1.0/modules/dc/), Syndication (http://purl.org/rss/1.0/modules/syndication/), and Taxonomy (http://purl.org/rss/1.0/modules/taxonomy/)

    By reading further, we see that

    XML::RSS also has support for "non-standard" RSS 1.0 modularization at the channel, image, item, and textinput levels. Parsing an RSS document grabs any elements of other namespaces which might appear. XML::RSS also allows the inclusion of arbitrary namespaces and associated elements when building RSS documents. For example, to add elements of a made-up "My" module, first declare the namespace by associating a prefix with a URI:
    $rss->add_module(prefix=>'my', uri=>'http://purl.org/my/rss/module/');
    Then proceed as usual:
    $rss->add_item (title=>$title, link=>$link, my=>{ rating=>$rating });
    Check module's POD for more information.

    Keep in mind that the sited documentation referes to XML::RSS version 1.10.

    Hope this helps.

    BR

      Thanks for the info. I've got the nonstandard module stuff working fine, it's just that Google Base seems to want items with multiple values as a series of identical elements:
      <g:label>Label 1</g:label> <g:label>Label 2</g:label>
      But XML:RSS doesn't seem to support outputting that type of XML, at least not that I can tell. For nonstandard namespace elements with a single value, it's working fine.