void yaz_marc_add_controlfield_xml(yaz_marc_t mt, const xmlNode *ptr_tag, const xmlNode *ptr_data) { struct yaz_marc_node *n = yaz_marc_add_node(mt); n->which = YAZ_MARC_CONTROLFIELD; n->u.controlfield.tag = nmem_text_node_cdata(ptr_tag, mt->nmem); n->u.controlfield.data = nmem_text_node_cdata(ptr_data, mt->nmem); }
void yaz_marc_add_datafield_xml(yaz_marc_t mt, const xmlNode *ptr_tag, const char *indicator, size_t indicator_len) { struct yaz_marc_node *n = yaz_marc_add_node(mt); n->which = YAZ_MARC_DATAFIELD; n->u.datafield.tag = nmem_text_node_cdata(ptr_tag, mt->nmem); n->u.datafield.indicator = nmem_strdupn(mt->nmem, indicator, indicator_len); n->u.datafield.subfields = 0; /* make subfield_pp the current (last one) */ mt->subfield_pp = &n->u.datafield.subfields; }
struct icu_chain *icu_chain_xml_config(const xmlNode *xml_node, int sort, UErrorCode *status) { xmlNode *node = 0; int no_errors = 0; struct icu_chain *chain = 0; NMEM nmem = 0; *status = U_ZERO_ERROR; if (xml_node && xml_node->type == XML_ELEMENT_NODE) { const char *xml_locale = yaz_xml_get_prop((xmlNode *) xml_node, "locale"); if (xml_locale) chain = icu_chain_create((const char *) xml_locale, sort, status); } if (!chain) return 0; nmem = nmem_create(); for (node = xml_node->children; node; node = node->next) { char *rule = 0; struct icu_chain_step *step = 0; const char *attr_str; nmem_reset(nmem); if (node->type != XML_ELEMENT_NODE) continue; attr_str = yaz_xml_get_prop(node, "rule%s", &rule); if (attr_str) { yaz_log(YLOG_WARN, "Unsupported attribute '%s' for " "element '%s'", attr_str, node->name); no_errors++; } if (!rule && node->children) rule = nmem_text_node_cdata(node->children, nmem); if (!rule && strcmp((const char *) node->name, "display")) { yaz_log(YLOG_WARN, "Missing attribute 'rule' for element %s", (const char *) node->name); no_errors++; continue; } if (!strcmp((const char *) node->name, "casemap")) step = icu_chain_insert_step(chain, ICU_chain_step_type_casemap, rule, status); else if (!strcmp((const char *) node->name, "transform")) step = icu_chain_insert_step(chain, ICU_chain_step_type_transform, rule, status); else if (!strcmp((const char *) node->name, "transliterate")) step = icu_chain_insert_step(chain, ICU_chain_step_type_transliterate, rule, status); else if (!strcmp((const char *) node->name, "tokenize")) step = icu_chain_insert_step(chain, ICU_chain_step_type_tokenize, rule, status); else if (!strcmp((const char *) node->name, "display")) step = icu_chain_insert_step(chain, ICU_chain_step_type_display, rule, status); else if (!strcmp((const char *) node->name, "stemming")) step = icu_chain_insert_step(chain, YAZ_chain_step_type_stemming, rule, status); else if (!strcmp((const char *) node->name, "join")) step = icu_chain_insert_step(chain, ICU_chain_step_type_join, rule, status); else if (!strcmp((const char *) node->name, "normalize")) { yaz_log(YLOG_WARN, "Element %s is deprecated. " "Use transform instead", node->name); step = icu_chain_insert_step(chain, ICU_chain_step_type_transform, rule, status); } else if (!strcmp((const char *) node->name, "index") || !strcmp((const char *) node->name, "sortkey")) { yaz_log(YLOG_WARN, "Element %s is no longer needed. " "Remove it from the configuration", node->name); } else { yaz_log(YLOG_WARN, "Unknown element %s", node->name); no_errors++; continue; } if (!step) { yaz_log(YLOG_WARN, "Step not created for %s", node->name); no_errors++; } if (step && U_FAILURE(*status)) { yaz_log(YLOG_WARN, "ICU Error %d %s for element %s, rule %s", *status, u_errorName(*status), node->name, rule ? rule : ""); no_errors++; break; } } nmem_destroy(nmem); if (no_errors) { icu_chain_destroy(chain); return 0; } return chain; }
static char *strVal(const xmlNode *ptr_cdata, ODR odr) { return nmem_text_node_cdata(ptr_cdata, odr_getmem(odr)); }