develooper Front page | perl.perl4lib | Postings from April 2018

Re: Converting XML to MARC without reading a file?

Thread Previous | Thread Next
From:
David Cook
Date:
April 23, 2018 01:38
Subject:
Re: Converting XML to MARC without reading a file?
Message ID:
CACVmdZTpudT5MzqxFHMR5BsEu=0rjHg-aDa2u8juJ1Yezd5_mg@mail.gmail.com
 The downside of that is that you would be parsing your XML twice though.
Once with XML::Twig and once with MARC::File::XML.

That said, if you have a huge result set, it would probably be better (or
even necessary) to use XML::Twig::parseurl() or roll your own using LWP
with callbacks and a pull parser like
http://search.cpan.org/dist/XML-LibXML/lib/XML/LibXML/Parser.pod#Pull_Parser_(Reader)
.

I built a OAI-PMH harvester for Koha, which can pull down a lot of huge
MARCXML records; I have a process handling the HTTP request with LWP and it
writes the XML to a pipe in chunks using a callback. I have a second
process read from the pipe using XML::LibXML::Reader and for each MARCXML
record that comes through it uses "new_from_xml()".

It works really really well.

On Thu, Apr 19, 2018 at 10:34 AM, Karl Billeter <kbilleter@gmail.com> wrote:

> On Thu, Apr 19, 2018 at 12:25:05AM +0000, Andy Kohler wrote:
>
> > Problem: Converting from MARCXML via MARC::File::XML seems to require
> > reading the records from a file.  I've already got the XML stored in a
> > variable, retrieved via LWP::Simple->get().
> >
> > Do I have to write the XML to a file, then read it in again to convert
> it?
> > Or am I just missing something obvious?
>
> Looking at the module documentation new_from_xml() should work but only
> for a
> single record chunk.  I'd probably use that and something like XML::Twig to
> split the records.
>
> K
>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About