+ if (mt->enable_collection == collection_first)
+ {
+ wrbuf_printf(wr, "<collection xmlns=\"%s\">\n", ns);
+ mt->enable_collection = collection_second;
+ }
+ wrbuf_printf(wr, "<%s", record_name[turbo]);
+ }
+ else
+ {
+ wrbuf_printf(wr, "<%s xmlns=\"%s\"", record_name[turbo], ns);
+ }
+ if (format)
+ wrbuf_printf(wr, " format=\"%.80s\"", format);
+ if (type)
+ wrbuf_printf(wr, " type=\"%.80s\"", type);
+ wrbuf_printf(wr, ">\n");
+ for (n = mt->nodes; n; n = n->next)
+ {
+ struct yaz_marc_subfield *s;
+
+ switch(n->which)
+ {
+ case YAZ_MARC_DATAFIELD:
+
+ wrbuf_printf(wr, " <%s", datafield_name[turbo]);
+ if (!turbo)
+ wrbuf_printf(wr, " tag=\"");
+ wrbuf_iconv_write_cdata(wr, mt->iconv_cd, n->u.datafield.tag,
+ strlen(n->u.datafield.tag));
+ if (!turbo)
+ wrbuf_printf(wr, "\"");
+ if (n->u.datafield.indicator)
+ {
+ int i;
+ for (i = 0; n->u.datafield.indicator[i]; i++)
+ {
+ wrbuf_printf(wr, " %s%d=\"", indicator_name[turbo], i+1);
+ wrbuf_iconv_write_cdata(wr, mt->iconv_cd,
+ n->u.datafield.indicator+i, 1);
+ wrbuf_iconv_puts(wr, mt->iconv_cd, "\"");
+ }
+ }
+ wrbuf_printf(wr, ">\n");
+ for (s = n->u.datafield.subfields; s; s = s->next)
+ {
+ size_t using_code_len = get_subfield_len(mt, s->code_data,
+ identifier_length);
+ wrbuf_printf(wr, " <%s", subfield_name[turbo]);
+ if (!turbo)
+ {
+ wrbuf_printf(wr, " code=\"");
+ wrbuf_iconv_write_cdata(wr, mt->iconv_cd,
+ s->code_data, using_code_len);
+ wrbuf_iconv_puts(wr, mt->iconv_cd, "\">");
+ }
+ else
+ {
+ element_name_append_attribute_value(mt, wr, "code", s->code_data, using_code_len);
+ wrbuf_puts(wr, ">");
+ }
+ wrbuf_iconv_write_cdata(wr, mt->iconv_cd,
+ s->code_data + using_code_len,
+ strlen(s->code_data + using_code_len));
+ marc_iconv_reset(mt, wr);
+ wrbuf_printf(wr, "</%s", subfield_name[turbo]);
+ if (turbo)
+ element_name_append_attribute_value(mt, wr, 0, s->code_data, using_code_len);
+ wrbuf_puts(wr, ">\n");
+ }
+ wrbuf_printf(wr, " </%s", datafield_name[turbo]);
+ /* TODO Not CDATA */
+ if (turbo)
+ wrbuf_iconv_write_cdata(wr, mt->iconv_cd, n->u.datafield.tag,
+ strlen(n->u.datafield.tag));
+ wrbuf_printf(wr, ">\n");
+ break;
+ case YAZ_MARC_CONTROLFIELD:
+ wrbuf_printf(wr, " <%s", controlfield_name[turbo]);
+ if (!turbo)
+ {
+ wrbuf_printf(wr, " tag=\"");
+ wrbuf_iconv_write_cdata(wr, mt->iconv_cd, n->u.controlfield.tag,
+ strlen(n->u.controlfield.tag));
+ wrbuf_iconv_puts(wr, mt->iconv_cd, "\">");
+ }
+ else
+ {
+ /* TODO convert special */
+ wrbuf_iconv_write_cdata(wr, mt->iconv_cd, n->u.controlfield.tag,
+ strlen(n->u.controlfield.tag));
+ wrbuf_iconv_puts(wr, mt->iconv_cd, ">");
+ }
+ wrbuf_iconv_write_cdata(wr, mt->iconv_cd,
+ n->u.controlfield.data,
+ strlen(n->u.controlfield.data));
+ marc_iconv_reset(mt, wr);
+ wrbuf_printf(wr, "</%s", controlfield_name[turbo]);
+ /* TODO convert special */
+ if (turbo)
+ wrbuf_iconv_write_cdata(wr, mt->iconv_cd, n->u.controlfield.tag,
+ strlen(n->u.controlfield.tag));
+ wrbuf_puts(wr, ">\n");
+ break;
+ case YAZ_MARC_COMMENT:
+ wrbuf_printf(wr, "<!-- ");
+ wrbuf_puts(wr, n->u.comment);
+ wrbuf_printf(wr, " -->\n");
+ break;
+ case YAZ_MARC_LEADER:
+ wrbuf_printf(wr, " <%s>", leader_name[turbo]);
+ wrbuf_iconv_write_cdata(wr,
+ 0 , /* no charset conversion for leader */
+ n->u.leader, strlen(n->u.leader));
+ wrbuf_printf(wr, "</%s>\n", leader_name[turbo]);
+ }