+ if (reader)
+ {
+ int ret;
+ while ((ret = xmlTextReaderRead(reader)) == 1)
+ {
+ int type = xmlTextReaderNodeType(reader);
+ if (type == XML_READER_TYPE_ELEMENT)
+ {
+ const char *name = (const char *)
+ xmlTextReaderLocalName(reader);
+ if (!strcmp(name, "record"))
+ {
+ xmlNodePtr ptr = xmlTextReaderExpand(reader);
+
+ int r = yaz_marc_read_xml(mt, ptr);
+ if (r)
+ fprintf(stderr, "yaz_marc_read_xml failed\n");
+ else
+ {
+ yaz_marc_write_mode(mt, wrbuf);
+
+ fputs(wrbuf_cstr(wrbuf), stdout);
+ wrbuf_rewind(wrbuf);
+ }
+ }
+ }
+ }
+ }
+#else
+ xmlDocPtr doc = xmlParseFile(fname);
+ if (doc)
+ {
+ xmlNodePtr ptr = xmlDocGetRootElement(doc);
+ for (; ptr; ptr = ptr->next)
+ {
+ if (ptr->type == XML_ELEMENT_NODE)
+ {
+ if (!strcmp((const char *) ptr->name, "collection"))
+ {
+ ptr = ptr->children;
+ continue;
+ }
+ if (!strcmp((const char *) ptr->name, "record"))
+ {
+ int r = yaz_marc_read_xml(mt, ptr);
+ if (r)
+ fprintf(stderr, "yaz_marc_read_xml failed\n");
+ else
+ {
+ yaz_marc_write_mode(mt, wrbuf);
+
+ fputs(wrbuf_cstr(wrbuf), stdout);
+ wrbuf_rewind(wrbuf);
+ }
+ }
+ }
+ }
+ xmlFreeDoc(doc);