- if (!turbo) {
- ptr_subfield = xmlNewTextChild(
- ptr, ns_record,
- BAD_CAST "subfield", BAD_CAST wrbuf_cstr(wr_cdata));
- wrbuf_rewind(wr_cdata);
- wrbuf_iconv_write(wr_cdata, mt->iconv_cd,s->code_data, using_code_len);
- xmlNewProp(ptr_subfield, BAD_CAST "code",
- BAD_CAST wrbuf_cstr(wr_cdata));
- }
- else { // Turbo format
- wrbuf_rewind(subfield_name);
- wrbuf_puts(subfield_name, "s");
- // TODO Map special codes to something possible for XML ELEMENT names
- if ((s->code_data[0] >= '0' && s->code_data[0] <= '9') ||
- (s->code_data[0] >= 'a' && s->code_data[0] <= 'z') ||
- (s->code_data[0] >= 'A' && s->code_data[0] <= 'Z'))
- {
- wrbuf_iconv_write(subfield_name, mt->iconv_cd,s->code_data, using_code_len);
- }
- else {
- char buffer[2*using_code_len + 1];
- int index;
- for (index = 0; index < using_code_len; index++) {
- sprintf(buffer + 2*index, "%02X", (unsigned char) s->code_data[index] & 0xFF);
- };
- buffer[2*(index+1)] = 0;
- wrbuf_puts(subfield_name, "-");
- wrbuf_puts(subfield_name, buffer);
- yaz_log(YLOG_WARN, "Using numeric value in element name: %s", buffer);
- }
- ptr_subfield = xmlNewTextChild(ptr, ns_record,
- BAD_CAST wrbuf_cstr(subfield_name),
- BAD_CAST wrbuf_cstr(wr_cdata));
+ wrbuf_rewind(subfield_name);
+ wrbuf_puts(subfield_name, "s");
+ not_written = element_name_append_attribute_value(mt, subfield_name, 0, s->code_data, using_code_len) != 0;
+ ptr_subfield = xmlNewTextChild(ptr, ns_record,
+ BAD_CAST wrbuf_cstr(subfield_name),
+ BAD_CAST wrbuf_cstr(wr_cdata));
+ if (not_written)
+ {
+ /* Generate code attribute value and add */
+ wrbuf_rewind(wr_cdata);
+ wrbuf_iconv_write(wr_cdata, mt->iconv_cd,s->code_data, using_code_len);
+ xmlNewProp(ptr_subfield, BAD_CAST "code", BAD_CAST wrbuf_cstr(wr_cdata));