+/** \brief adds a attribute value to the element name if it is plain chars
+
+ If not, and if the attribute name is not null, it will append a
+ attribute element with the value if attribute name is null it will
+ return a non-zero value meaning it couldnt handle the value.
+*/
+static int element_name_append_attribute_value(
+ yaz_marc_t mt, WRBUF buffer,
+ const char *attribute_name, char *code_data, size_t code_len)
+{
+ /* TODO Map special codes to something possible for XML ELEMENT names */
+
+ int encode = 0;
+ int index = 0;
+ int success = 0;
+ for (index = 0; index < code_len; index++)
+ {
+ if (!((code_data[index] >= '0' && code_data[index] <= '9') ||
+ (code_data[index] >= 'a' && code_data[index] <= 'z') ||
+ (code_data[index] >= 'A' && code_data[index] <= 'Z')))
+ encode = 1;
+ }
+ /* 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);
+ else
+ success = -1;
+
+ if (encode && attribute_name)
+ wrbuf_printf(buffer, "\""); /* return error if we couldn't handle it.*/
+ return success;
+}
+