+struct icu_chain * icu_chain_xml_config(xmlNode *xml_node,
+ UErrorCode * status){
+
+ xmlNode *node = 0;
+ struct icu_chain * chain = 0;
+
+ if (!xml_node
+ ||xml_node->type != XML_ELEMENT_NODE
+ || strcmp((const char *) xml_node->name, "icu_chain"))
+
+ return 0;
+
+ xmlChar *xml_id = xmlGetProp(xml_node, (xmlChar *) "id");
+ xmlChar *xml_locale = xmlGetProp(xml_node, (xmlChar *) "locale");
+
+ if (!xml_id || !strlen((const char *) xml_id)
+ || !xml_locale || !strlen((const char *) xml_locale))
+ return 0;
+
+ chain = icu_chain_create((const uint8_t *) xml_id,
+ (const uint8_t *) xml_locale);
+
+ xmlFree(xml_id);
+ xmlFree(xml_locale);
+ if (!chain)
+ return 0;
+
+ for (node = xml_node->children; node; node = node->next)
+ {
+ if (node->type != XML_ELEMENT_NODE)
+ continue;
+
+ xmlChar *xml_rule = xmlGetProp(node, (xmlChar *) "rule");
+ struct icu_chain_step * step = 0;
+
+ if (!strcmp((const char *) node->name,
+ (const char *) "casemap")){
+ step = icu_chain_insert_step(chain, ICU_chain_step_type_casemap,
+ (const uint8_t *) xml_rule, status);
+ }
+ else if (!strcmp((const char *) node->name,
+ (const char *) "normalize")){
+ step = icu_chain_insert_step(chain, ICU_chain_step_type_normalize,
+ (const uint8_t *) xml_rule, status);
+ }
+ else if (!strcmp((const char *) node->name,
+ (const char *) "tokenize")){
+ step = icu_chain_insert_step(chain, ICU_chain_step_type_tokenize,
+ (const uint8_t *) xml_rule, status);
+ }
+ else if (!strcmp((const char *) node->name,
+ (const char *) "display")){
+ step = icu_chain_insert_step(chain, ICU_chain_step_type_display,
+ (const uint8_t *) "", status);
+ }
+ else if (!strcmp((const char *) node->name,
+ (const char *) "normal")){
+ step = icu_chain_insert_step(chain, ICU_chain_step_type_norm,
+ (const uint8_t *) "", status);
+ }
+ else if (!strcmp((const char *) node->name,
+ (const char *) "sort")){
+ step = icu_chain_insert_step(chain, ICU_chain_step_type_sort,
+ (const uint8_t *) "", status);
+ }
+
+ xmlFree(xml_rule);
+ if (!step || U_FAILURE(*status)){
+ icu_chain_destroy(chain);
+ return 0;
+ }
+
+
+ }
+
+ return chain;