+ 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]);
+ }
+ }
+ wrbuf_printf(wr, "</%s>\n", record_name[turbo]);
+ return 0;
+}
+
+static int yaz_marc_write_marcxml_ns(yaz_marc_t mt, WRBUF wr,
+ const char *ns,
+ const char *format,
+ const char *type,
+ int turbo)
+{
+ if (mt->write_using_libxml2)