The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Google::Merchant - provide Google shop with product info

INHERITANCE

 Google::Merchant
   is a XML::Compile::Cache
   is a XML::Compile::Schema
   is a XML::Compile

 Google::Merchant is extended by
   Google::Merchant::AtomFeed

SYNOPSIS

  my $feed = Google::Merchant::AtomFeed->new
    ( title   => 'My Webshop'
    , website => 'https://webshop.example.org'
    );

  $feed->addItem
    ( # feed fields
      title   => 'washing machine'
    , webpage => "$website/EAN1234.html"

      # google base fields
    , id      => 'EAN1234'
    , price   => '12.34 EUR'
    );

  $feed->write($filename);

DESCRIPTION

With the Merchant interface, shop-owners inform Google which products they have for sale. Read the documentation at Google

Google provides two XML syntaxes to denote product information (and a few other formats). This distribution can be used to produce files in the correct syntax. On the moment, only the feed of Atoms are implemented, although RSS should not be too hard to add. An attempt is made to hide the difference between the two in the here provided interface.

This module can not read merchant files. As you will also discover in the examples shown by Google: they do not use the schema themselves, nearly all examples will fail validation! Especially, the strict order of elements in a sequence is ignored by Google's examples.

See documentation in base class.

METHODS

See documentation in base class.

Constructors

See documentation in base class.

Google::Merchant->new(OPTIONS)
 -Option            --Defined in          --Default
  allow_undeclared    XML::Compile::Cache   <false>
  any_element         XML::Compile::Cache   'SKIP_ALL'
  block_namespace     XML::Compile::Schema  []
  hook                XML::Compile::Schema  undef
  hooks               XML::Compile::Schema  []
  ignore_unused_tags  XML::Compile::Schema  <false>
  key_rewrite         XML::Compile::Schema  []
  opts_readers        XML::Compile::Cache   []
  opts_rw             XML::Compile::Cache   []
  opts_writers        XML::Compile::Cache   []
  parser_options      XML::Compile          <many>
  prefixes            XML::Compile::Cache   <smart>
  schema_dirs         XML::Compile          undef
  string_format                             'HTML'
  title                                     <required>
  typemap             XML::Compile::Cache   {}
  website                                   <required>
  xsi_type            XML::Compile::Cache   {}
allow_undeclared => BOOLEAN
any_element => CODE|'TAKE_ALL'|'SKIP_ALL'|'ATTEMPT'|'SLOPPY'
block_namespace => NAMESPACE|TYPE|HASH|CODE|ARRAY
hook => ARRAY-WITH-HOOKDATA | HOOK
hooks => ARRAY-OF-HOOK
ignore_unused_tags => BOOLEAN|REGEXP
key_rewrite => HASH|CODE|ARRAY-of-HASH-and-CODE
opts_readers => HASH|ARRAY-of-PAIRS
opts_rw => HASH|ARRAY-of-PAIRS
opts_writers => HASH|ARRAY-of-PAIRS
parser_options => HASH|ARRAY
prefixes => HASH|ARRAY-of-PAIRS
schema_dirs => DIRECTORY|ARRAY-OF-DIRECTORIES
string_format => 'TEXT'|'HTML'|'XHTML'

How are your text strings formatted by default? Google itself does not specify the content of the string elements (elements of type stringAttrValueType -which isn't an attribute type!) However, we do need to diffentiate between strings which already have entities encoded or not. HTML encoded strings are included as CDATA if they contain an ampersand '&'.

title => STRING
typemap => HASH|ARRAY
website => URI
xsi_type => HASH|ARRAY

Accessors

See documentation in base class.

$obj->addHook(HOOKDATA|HOOK|undef)

See "Accessors" in XML::Compile::Schema

$obj->addHooks(HOOK, [HOOK, ...])

See "Accessors" in XML::Compile::Schema

$obj->addKeyRewrite(PREDEF|CODE|HASH, ...)

See "Accessors" in XML::Compile::Schema

$obj->addSchemaDirs(DIRECTORIES|FILENAME)
Google::Merchant->addSchemaDirs(DIRECTORIES|FILENAME)

See "Accessors" in XML::Compile

$obj->addSchemas(XML, OPTIONS)

See "Accessors" in XML::Compile::Schema

$obj->addTypemap(PAIR)

See "Accessors" in XML::Compile::Schema

$obj->addTypemaps(PAIRS)

See "Accessors" in XML::Compile::Schema

$obj->allowUndeclared([BOOLEAN])

See "Accessors" in XML::Compile::Cache

$obj->anyElement('ATTEMPT'|'SLOPPY'|'SKIP_ALL'|'TAKE_ALL'|CODE)

See "Accessors" in XML::Compile::Cache

$obj->blockNamespace(NAMESPACE|TYPE|HASH|CODE|ARRAY)

See "Accessors" in XML::Compile::Schema

$obj->hooks()

See "Accessors" in XML::Compile::Schema

$obj->typemap([HASH|ARRAY|PAIRS])

See "Accessors" in XML::Compile::Cache

$obj->useSchema(SCHEMA, [SCHEMA])

See "Accessors" in XML::Compile::Schema

$obj->xsiType([HASH|ARRAY|LIST])

See "Accessors" in XML::Compile::Cache

Prefix management

See documentation in base class.

$obj->learnPrefixes(NODE)

See "Prefix management" in XML::Compile::Cache

$obj->prefix(PREFIX)

See "Prefix management" in XML::Compile::Cache

$obj->prefixFor(URI)

See "Prefix management" in XML::Compile::Cache

$obj->prefixed(TYPE|(NAMESPACE,LOCAL))

See "Prefix management" in XML::Compile::Cache

$obj->prefixes([PAIRS|ARRAY|HASH])

See "Prefix management" in XML::Compile::Cache

Compilers

See documentation in base class.

$obj->addCompileOptions(['READERS'|'WRITERS'|'RW'], OPTIONS)

See "Compilers" in XML::Compile::Cache

$obj->compile(('READER'|'WRITER'), TYPE, OPTIONS)

See "Compilers" in XML::Compile::Schema

$obj->compileAll(['READERS'|'WRITERS'|'RW', [NAMESPACE]])

See "Compilers" in XML::Compile::Cache

$obj->dataToXML(NODE|REF-XML-STRING|XML-STRING|FILENAME|FILEHANDLE|KNOWN)
Google::Merchant->dataToXML(NODE|REF-XML-STRING|XML-STRING|FILENAME|FILEHANDLE|KNOWN)

See "Compilers" in XML::Compile

$obj->initParser(OPTIONS)
Google::Merchant->initParser(OPTIONS)

See "Compilers" in XML::Compile

$obj->reader(TYPE|NAME, OPTIONS)

See "Compilers" in XML::Compile::Cache

$obj->template('XML'|'PERL'|'TREE', ELEMENT, OPTIONS)

See "Compilers" in XML::Compile::Schema

$obj->writer(TYPE|NAME)

See "Compilers" in XML::Compile::Cache

Administration

See documentation in base class.

$obj->declare('READER'|'WRITER'|'RW', TYPE|ARRAY-of-TYPES, OPTIONS)

See "Administration" in XML::Compile::Cache

$obj->doesExtend(EXTTYPE, BASETYPE)

See "Administration" in XML::Compile::Schema

$obj->elements()

See "Administration" in XML::Compile::Schema

$obj->findName(NAME)

See "Administration" in XML::Compile::Cache

$obj->findSchemaFile(FILENAME)
Google::Merchant->findSchemaFile(FILENAME)

See "Administration" in XML::Compile

$obj->importDefinitions(XMLDATA, OPTIONS)

See "Administration" in XML::Compile::Schema

$obj->knownNamespace(NAMESPACE|PAIRS)
Google::Merchant->knownNamespace(NAMESPACE|PAIRS)

See "Administration" in XML::Compile

$obj->namespaces()

See "Administration" in XML::Compile::Schema

$obj->printIndex([FILEHANDLE], OPTIONS)

See "Administration" in XML::Compile::Cache

$obj->types()

See "Administration" in XML::Compile::Schema

$obj->walkTree(NODE, CODE)

See "Administration" in XML::Compile

Items

$obj->addItem(OPTIONS)

The list of available OPTIONS is huge: all the fields which can be included in the atom. Not only a few which are RSS/Atom specific (see extension) but also dozens of fields specified by Google.

$obj->stringFormat()

Returns the default text format.

Feed handling

$obj->write(FILENAME, OPTIONS)
 -Option  --Default
  beautify  0
  doc       <created internally>
  gzip      <undef>
beautify => 0|1|2

XML::LibXML output format parameter.

doc => XML::LibXML::Document object
gzip => 0..8

Libxml2 (the library which is used by XML::LibXML) can be compiled with gzip support. A higher compression factor may result in a smaller output file.

DETAILS

See documentation in base class.

Comparison

See documentation in base class.

Collecting definitions

See documentation in base class.

Addressing components

See documentation in base class.

Representing data-structures

See documentation in base class.

Schema hooks

See documentation in base class.

Typemaps

See documentation in base class.

Handling xsi:type

See documentation in base class.

Key rewrite

See documentation in base class.

Item fields

The RSS interface defines an 'Item', and Google uses that term as well to describe product listings. The Atom interface refers to these as 'Entry' elements.

The Atom interface defines 12 fields, of which Google only uses three: the title, link, and summary. To reduce the gap between the Atom and RSS interface, you pass these three values via parameters title, webpage, and description respectively.

Google defined a huge list of parameters for any product. Look in the examples/ directory of this module for the template which lists the fields and explains their limitations. Most of these fields are described on the 'feed specification' on the google support website.

  $feed->addItem
    ( # feed fields
      title       => 'washing machine'
    , webpage     => "$website/EAN1234.html"
    , description => "Best you can buy"

      # google base fields
    , id      => 'EAN1234'
    );

  $feed->write($filename);

string values

String values (elements of type g:stringAttrValueType) can either be represented as HTML/XHTML or (plain) TEXT. This difference minor but crucial: when HTML is passed as TEXT, you may get double encoding of entities. For instance, '&quot;' may become '&amp;quot;'.

Set the best default with new(string_format). Now, per field you may diverge from the default:

  my $feed = Google::Merchant::AtomFeed->new(...
    , string_format => 'HTML'
    );
  
  $feed->addItem
    ( brand => '&gt;&quot;&lt'     # default, here HTML
    , isbn  => { type => 'TEXT'
               , _    => '<">'
               }
    );

DESCRIPTIONS

See documentation in base class.

SEE ALSO

This module is part of Google-Merchant distribution version 0.10, built on May 13, 2013. Website: http://perl.overmeer.net/xml-compile/

Other distributions in this suite: XML::Compile, XML::Compile::SOAP, XML::Compile::SOAP12, XML::Compile::SOAP::Daemon, XML::Compile::SOAP::WSA, XML::Compile::C14N, XML::Compile::WSS, XML::Compile::WSS::Signature, XML::Compile::Tester, XML::Compile::Cache, XML::Compile::Dumper, XML::Compile::RPC, XML::Rewrite, XML::eXistDB, and XML::LibXML::Simple.

Please post questions or ideas to the mailinglist at http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/xml-compile . For live contact with other developers, visit the #xml-compile channel on irc.perl.org.

LICENSE

Copyrights 2013 by [Mark Overmeer]. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html