Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Document use of MARCXML with an example #134

Closed
nichtich opened this issue Apr 29, 2019 · 5 comments
Closed

Document use of MARCXML with an example #134

nichtich opened this issue Apr 29, 2019 · 5 comments

Comments

@nichtich
Copy link

nichtich commented Apr 29, 2019

We are still trying to find out how to parse and serialize MARCXML. I then stumbled upon #73 (make it simpler) but one or two examples in the documentation may be enough to start with:

  • how to read a full MARCXML file
  • how to read a stream of records from a MARCXML file (maybe this helps)
  • how to serialize MARC records to XML

P.S: See also this help request.

@edsu
Copy link
Owner

edsu commented Apr 30, 2019

Sure, I'd be happy to merge those docs. Although the referenced ticket, which I've intentionally left open, makes it sound like there could be a preferable API for reading/writing XML?

@edsu
Copy link
Owner

edsu commented Apr 30, 2019

@nichtich do you know if lxml.etree.iterparse reads the entire document into memory, and then iterates over that?

@edsu
Copy link
Owner

edsu commented Apr 30, 2019

@nichtich Will this new documentation help clarify the current state of affairs with XML and JSON? It can always get updated if there does turn out to be progress on #73. If you have any suggestions for improving it please send them along.

@nichtich
Copy link
Author

nichtich commented May 1, 2019

@edsu Thanks for the new documentation that's very helpful, I did not know about map_xml. Writing XML is possible nevertheless. The following is possibly no beautiful Python but should work:

# write XML header to file object
file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
file.write('<collection xmlns="http://www.loc.gov/MARC21/slim">\n')

# write records
for record in records:
     file.write(marcxml.record_to_xml(record).decode("utf-8"))
     file.write('\n')

# write XML footer
file.write('</collection>')
file.close()

@edsu
Copy link
Owner

edsu commented May 1, 2019

That would be better expressed in a separate pull request. If the documentation suffices for now I'm going to close this.

@edsu edsu closed this as completed May 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants