Re: Converting XML to MARC without reading a file?
[email protected] (David Cook) Thu, 19 Apr 2018 08:33:33 +0000
| Newsgroups | perl.perl4lib |
|---|---|
| Message-ID | <CACVmdZQqS-jHQBuk_K5qBXR+_zmODU=ydAvfzQMQ4byboaDGCg@mail.gmail.com> |
--089e082037a8fa774b056a2f6dd3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I was thinking the same thing because that's what we do in Koha, but I think Andy is getting back more than 1 XML record per HTTP request so I don't think that will work. That said he could use a XML streaming parser and LWP with callbacks and then pass each individual record to new_from_xml. On Thu, 19 Apr 2018, 6:24 PM Dr. Saiful Amin <[email protected]> wrote: > > On Thu, Apr 19, 2018 at 5:55 AM, Andy Kohler <[email protected]> wrote= : > >> Hi - >> >> I'm pulling records from the WorldCat Search API in MARCXML, and need to >> convert them to binary MARC for further evaluation, which I'll do via >> MARC::Record. >> >> 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? >> > > =E2=80=8BThe function new_from_xml() should work without filehandle I thi= nk. I'm > pulling a bunch of MARCXML records from a database and the code looks lik= e > this: > > while ( my $row =3D $sth->fetchrow_hashref() ) { > my $marcxml =3D $row->{'marcxml'}; > my $record =3D MARC::Record->new_from_xml( $marcxml, 'UTF-8' ); > ... > }=E2=80=8B > > -- > Saiful Amin > --089e082037a8fa774b056a2f6dd3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto">I was thinking the same thing because that's what we = do in Koha, but I think Andy is getting back more than 1 XML record per HTT= P request so I don't think that will work.<div dir=3D"auto"><br></div><= div dir=3D"auto">That said he could use a XML streaming parser and LWP with= callbacks and then pass each individual record to new_from_xml.=C2=A0</div= ><div dir=3D"auto"><br></div><div dir=3D"auto"><br></div></div><br><div cla= ss=3D"gmail_quote"><div dir=3D"ltr">On Thu, 19 Apr 2018, 6:24 PM Dr. Saiful= Amin <<a href=3D"mailto:[email protected]">[email protected]</a= >> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0= 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><= div class=3D"gmail_extra"><div class=3D"gmail_quote">On Thu, Apr 19, 2018 a= t 5:55 AM, Andy Kohler <span dir=3D"ltr"><<a href=3D"mailto:akohler726@g= mail.com" target=3D"_blank" rel=3D"noreferrer">[email protected]</a>>= </span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px= 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div di= r=3D"ltr"><div><div><div><div>Hi -<br><br></div>I'm pulling records fro= m the WorldCat Search API in MARCXML, and need to convert them to binary MA= RC for further evaluation, which I'll do via MARC::Record.<br><br></div= >Problem: Converting from MARCXML via MARC::File::XML seems to require read= ing the records from a file.=C2=A0 I've already got the XML stored in a= variable, retrieved via LWP::Simple->get().<br><br></div>Do I have to w= rite the XML to a file, then read it in again to convert it?=C2=A0 Or am I = just missing something obvious?<br></div></div></blockquote><div>=C2=A0<br>= <div class=3D"gmail_default">=E2=80=8BThe function <span style=3D"font-fami= ly:monospace,monospace">new_from_xml()</span> should work without filehandl= e I think. I'm pulling a bunch of MARCXML records from a database and t= he code looks like this:<br><br><span style=3D"font-family:monospace,monosp= ace">while ( my $row =3D $sth->fetchrow_hashref() ) {<br>=C2=A0=C2=A0=C2= =A0 my $marcxml =3D $row->{'marcxml'};<br>=C2=A0=C2=A0=C2=A0 my = $record =3D MARC::Record->new_from_xml( $marcxml, 'UTF-8' );<br>= =C2=A0=C2=A0=C2=A0 ...<br>}=E2=80=8B</span></div></div></div><div class=3D"= gmail_default"> <div class=3D"gmail_default"></div><div class=3D"gmail_extra"><br clear=3D"= all"><div><div class=3D"m_-6695182331789784495gmail_signature"><div dir=3D"= ltr">--<br>Saiful Amin<br></div></div></div> </div></div></div></div> </blockquote></div> --089e082037a8fa774b056a2f6dd3--