- if (!encode) {
- wrbuf_iconv_write(buffer, mt->iconv_cd, code_data, code_len);
- }
- else {
- char temp[2*code_len + 1];
- wrbuf_puts(buffer, "-");
- int index;
- for (index = 0; index < code_len; index++) {
- sprintf(temp+2*index, "%02X", (unsigned char) code_data[index] & 0xFF);
- };
- temp[2*code_len+1] = 0;
- wrbuf_puts(buffer, temp);
- yaz_log(YLOG_WARN, "Using numeric value in element name: %s", temp);
- }
+ // Add as attribute
+ if (encode && attribute_name)
+ wrbuf_printf(buffer, " %s=\"", attribute_name);
+
+ if (!encode || attribute_name)
+ wrbuf_iconv_write_cdata(buffer, mt->iconv_cd, code_data, code_len);
+ if (encode && attribute_name)
+ wrbuf_printf(buffer, "\"");
+ // return error if we couldn't handle it.
+ if (encode && !attribute_name);
+ return -1;
+ return 0;