X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fxml_to_opac.c;h=236bf8a48966ea6ebc06284c9923e7c76514b144;hp=e6735c92f8a3261a6dba1d5421dcae3a06111ad7;hb=f720562471a064dba92a465d999aa833e59d69b1;hpb=4c1a14ddb2c650b935bc8dff4dc3f8a98ff7531c diff --git a/src/xml_to_opac.c b/src/xml_to_opac.c index e6735c9..236bf8a 100644 --- a/src/xml_to_opac.c +++ b/src/xml_to_opac.c @@ -20,41 +20,14 @@ #include #if YAZ_HAVE_XML2 -#include -#include - -static int match_element(xmlNode *ptr, const char *elem) -{ - if (ptr->type == XML_ELEMENT_NODE && !xmlStrcmp(ptr->name, BAD_CAST elem)) - { - return 1; - } - return 0; -} - -static int match_xsd_string_n(xmlNodePtr ptr, const char *elem, NMEM nmem, - char **val, int *len) -{ - if (!match_element(ptr, elem)) - return 0; - ptr = ptr->children; - if (!ptr || ptr->type != XML_TEXT_NODE) - { - *val = ""; - return 1; - } - *val = nmem_strdup(nmem, (const char *) ptr->content); - if (len) - *len = xmlStrlen(ptr->content); - return 1; -} +#include "sru-p.h" static int match_element_next(xmlNode **ptr, const char *elem, NMEM nmem, char **val) { while (*ptr && (*ptr)->type != XML_ELEMENT_NODE) (*ptr) = (*ptr)->next; - if (*ptr && match_xsd_string_n(*ptr, elem, nmem, val, 0)) + if (*ptr && yaz_match_xsd_string_n_nmem(*ptr, elem, nmem, val, 0)) { *ptr = (*ptr)->next; return 1; @@ -69,7 +42,7 @@ static int match_v_next(xmlNode **ptr, const char *elem, NMEM nmem, while (*ptr && (*ptr)->type != XML_ELEMENT_NODE) (*ptr) = (*ptr)->next; *val = nmem_booldup(nmem, 0); - if (*ptr && match_element(*ptr, elem)) + if (*ptr && yaz_match_xsd_element(*ptr, elem)) { struct _xmlAttr *attr = (*ptr)->properties; @@ -95,7 +68,7 @@ static int match_v_next(xmlNode **ptr, const char *elem, NMEM nmem, } static int bibliographicRecord(yaz_marc_t mt, xmlNode *ptr, Z_External **ext, - yaz_iconv_t cd, NMEM nmem) + yaz_iconv_t cd, NMEM nmem, const Odr_oid *syntax) { int ret = 0; if (yaz_marc_read_xml(mt, ptr) == 0) @@ -103,8 +76,9 @@ static int bibliographicRecord(yaz_marc_t mt, xmlNode *ptr, Z_External **ext, WRBUF wr = wrbuf_alloc(); if (yaz_marc_write_iso2709(mt, wr) == 0) { - *ext = z_ext_record_oid_nmem(nmem, yaz_oid_recsyn_usmarc, - wrbuf_buf(wr), wrbuf_len(wr)); + *ext = z_ext_record_oid_nmem( + nmem, syntax ? syntax : yaz_oid_recsyn_usmarc, + wrbuf_buf(wr), wrbuf_len(wr)); ret = 1; } wrbuf_destroy(wr); @@ -133,7 +107,7 @@ static int volumes(xmlNode *ptr, Z_Volume ***volp, int *num, NMEM nmem) ptr = ptr->next; if (!ptr) break; - if (!match_element(ptr, "volume")) + if (!yaz_match_xsd_element(ptr, "volume")) return 0; ptr = ptr->next; } @@ -146,7 +120,7 @@ static int volumes(xmlNode *ptr, Z_Volume ***volp, int *num, NMEM nmem) ptr = ptr->next; if (!ptr) break; - if (!match_element(ptr, "volume")) + if (!yaz_match_xsd_element(ptr, "volume")) return 0; volume(ptr->children, (*volp) + i, nmem); ptr = ptr->next; @@ -186,7 +160,7 @@ static int circulations(xmlNode *ptr, Z_CircRecord ***circp, ptr = ptr->next; if (!ptr) break; - if (!match_element(ptr, "circulation")) + if (!yaz_match_xsd_element(ptr, "circulation")) return 0; ptr = ptr->next; } @@ -199,7 +173,7 @@ static int circulations(xmlNode *ptr, Z_CircRecord ***circp, ptr = ptr->next; if (!ptr) break; - if (!match_element(ptr, "circulation")) + if (!yaz_match_xsd_element(ptr, "circulation")) return 0; circulation(ptr->children, (*circp) + i, nmem); ptr = ptr->next; @@ -239,7 +213,7 @@ static int holdingsRecord(xmlNode *ptr, Z_HoldingsRecord **r, NMEM nmem) h->volumes = 0; while (ptr && ptr->type != XML_ELEMENT_NODE) ptr = ptr->next; - if (match_element(ptr, "volumes")) + if (yaz_match_xsd_element(ptr, "volumes")) { volumes(ptr->children, &h->volumes, &h->num_volumes, nmem); ptr = ptr->next; @@ -249,7 +223,7 @@ static int holdingsRecord(xmlNode *ptr, Z_HoldingsRecord **r, NMEM nmem) h->circulationData = 0; while (ptr && ptr->type != XML_ELEMENT_NODE) ptr = ptr->next; - if (match_element(ptr, "circulations")) + if (yaz_match_xsd_element(ptr, "circulations")) { circulations(ptr->children, &h->circulationData, &h->num_circulationData, nmem); @@ -260,7 +234,8 @@ static int holdingsRecord(xmlNode *ptr, Z_HoldingsRecord **r, NMEM nmem) static int yaz_xml_to_opac_ptr(yaz_marc_t mt, xmlNode *ptr, Z_OPACRecord **dst, - yaz_iconv_t cd, NMEM nmem) + yaz_iconv_t cd, NMEM nmem, + const Odr_oid *syntax) { int i; Z_External *ext = 0; @@ -269,14 +244,14 @@ static int yaz_xml_to_opac_ptr(yaz_marc_t mt, xmlNode *ptr, if (!nmem) nmem = yaz_marc_get_nmem(mt); - if (!match_element(ptr, "opacRecord")) + if (!yaz_match_xsd_element(ptr, "opacRecord")) return 0; ptr = ptr->children; while (ptr && ptr->type != XML_ELEMENT_NODE) ptr = ptr->next; - if (!match_element(ptr, "bibliographicRecord")) + if (!yaz_match_xsd_element(ptr, "bibliographicRecord")) return 0; - if (!bibliographicRecord(mt, ptr->children, &ext, cd, nmem)) + if (!bibliographicRecord(mt, ptr->children, &ext, cd, nmem, syntax)) return 0; *dst = opac = (Z_OPACRecord *) nmem_malloc(nmem, sizeof(*opac)); opac->num_holdingsData = 0; @@ -286,7 +261,7 @@ static int yaz_xml_to_opac_ptr(yaz_marc_t mt, xmlNode *ptr, ptr = ptr->next; while (ptr && ptr->type != XML_ELEMENT_NODE) ptr = ptr->next; - if (!match_element(ptr, "holdings")) + if (!yaz_match_xsd_element(ptr, "holdings")) return 0; ptr = ptr->children; @@ -298,7 +273,7 @@ static int yaz_xml_to_opac_ptr(yaz_marc_t mt, xmlNode *ptr, ptr = ptr->next; if (!ptr) break; - if (!match_element(ptr, "holding")) + if (!yaz_match_xsd_element(ptr, "holding")) return 0; ptr = ptr->next; } @@ -312,7 +287,7 @@ static int yaz_xml_to_opac_ptr(yaz_marc_t mt, xmlNode *ptr, ptr = ptr->next; if (!ptr) break; - if (!match_element(ptr, "holding")) + if (!yaz_match_xsd_element(ptr, "holding")) return 0; if (!holdingsRecord(ptr->children, opac->holdingsData + i, nmem)) return 0; @@ -322,13 +297,15 @@ static int yaz_xml_to_opac_ptr(yaz_marc_t mt, xmlNode *ptr, } int yaz_xml_to_opac(yaz_marc_t mt, const char *buf_in, size_t size_in, - Z_OPACRecord **dst, yaz_iconv_t cd, NMEM nmem) + Z_OPACRecord **dst, yaz_iconv_t cd, NMEM nmem, + const Odr_oid *syntax) { xmlDocPtr doc = xmlParseMemory(buf_in, size_in); int r = 0; if (doc) { - r = yaz_xml_to_opac_ptr(mt, xmlDocGetRootElement(doc), dst, cd, nmem); + r = yaz_xml_to_opac_ptr(mt, xmlDocGetRootElement(doc), dst, cd, nmem, + syntax); xmlFreeDoc(doc); } return r;