LibreCat / Catmandu-OAI

Catmandu modules for working with OAI repositories
https://metacpan.org/release/Catmandu-OAI
3 stars 2 forks source link

modify handler to use XML::Struct by default #3

Closed nichtich closed 10 years ago

nichtich commented 10 years ago

I removed the undocumented _metadata field that bloated the record and added a default handler for other metadata formats but "oai_dc", reusing the _metadata field. Handlers can also be simple code references, so it is easier to override the new default handler, for instance with XSLT.

nichtich commented 10 years ago

I added some fixes to Catmand::XML so transformation with XML::Struct could also be done in a fix. Instead of the proposed change, the DOM object should be passed for better performance. Serializing back XML should be avoided if possible.

phochste commented 10 years ago

Catmandu::Fix::Bind-s can be used to send DOM objects to xml fixes. i'll see if i can provide an example. You might want to write something like:

do
   xml_parser(field)
   xml_transform(...)
end

Where xml_parser is a Bind that can pass DOM to all fixes in a do-end block

nichtich commented 10 years ago

If Camandu::OAI passed the parsed DOM fragment unserialized it can already be processed with fixes from Catmandu::XML:

xml_transform(_metadata, file: 'script.xsl')
xml_read(_metadata, simple: 1)
...
xml_write(_metadata)

On 21. Juni 2014 06:53:13 MESZ, Patrick Hochstenbach notifications@github.com wrote:

Catmandu::Fix::Bind-s can be used to send DOM objects to xml fixes. i'll see if i can provide an example. You might want to write something like:

do xml_parser(field) xml_transform(...) end

Where xml_parser is a Bind that can pass DOM to all fixes in a do-end block


Reply to this email directly or view it on GitHub: https://github.com/LibreCat/Catmandu-OAI/pull/3#issuecomment-46744690

Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

phochste commented 10 years ago

Ok requires XML::Struct 0.19 to get this working. Will create a push a new version to CPAN

nichtich commented 10 years ago

Support of multiple handlers as implemented in 0.06 is better. I only doubt that the namespace Catmandu::Importer::OAI::Parser:: is the right place because these handlers can be used for other formats (e.g. SRU and unAPI) too. How about Catmandu::Parser::DOM:: for handlers that convert DOM objects into Perl hashes? Having yet another package for each XML-based format (dc, marcxml, ...) seems not a good choice of design.

I further need a 'none' handler/parser that just keeps the DOM without parsing (the raw handler serializes the DOM), so it can be processed with fixes. Maybe this is a better default? I'll experiment further with Catmandu::XML :-)

phochste commented 10 years ago

Sure! If we can refactor this out of Catmandu::SRU and Catmandu::OAI I will gladly help.

I'm a bit worried about moving DOM-s around in Catmandu because non of our fixes, exporter have any contract that they should cope with blessed objects. I think Binds can be of help here to create blocks of code and specialised fixes that do like DOM. These Binds are by design created to cope with non-JSON input. E.g. you can work on binary objects with current fixes if you can create a correct Bind.

I will try to create an example..first need to fight with my OSX to get XML::LibXSLT installed