edeposit / marcxml_parser

MARC XML / OAI parser, with few highlevel getters.
MIT License
4 stars 5 forks source link

Add ability to process multiple records. #20

Closed Bystroushaak closed 9 years ago

Bystroushaak commented 9 years ago

From email:

Hello,

I’m using your marcxml_parser in python. It’s great, thank you for building it! 

I was wondering if you could help me out with a problem. I’m trying to parse an xml file that contains multiple records (attached). Is it possible to parse more than one record?

My code is:

from marcxml_parser import MARCXMLRecord

with open (“data/socabs2015.xml”) as f:
    data = f.read()

rec = MARCXMLRecord(data)

print(rec.get_subfields(“100”, “a”))

This parses the first record in the xml file and prints the author name. However, I cannot work out how to print the author names from the rest of the records in the xml file.

Thank you for any help.

George
Bystroushaak commented 9 years ago

Implemented.

It should work like this:

from marcxml_parser import record_iterator

for rec in record_iterator(open("data/socabs2015.xml")):
    print rec.get_subfields("100", "a")
Bystroushaak commented 9 years ago

See http://marcxml-parser.readthedocs.org/en/latest/api/record.html#marcxml_parser.record.record_iterator for details.