28#include <libxml/tree.h>
35 for (; ptr; ptr = ptr->next)
37 if (ptr->type == XML_ELEMENT_NODE)
39 if (!strcmp((
const char *) ptr->name,
"subfield"))
41 size_t ctrl_data_len = 0;
42 char *ctrl_data_buf = 0;
43 const xmlNode *p = 0, *ptr_code = 0;
44 struct _xmlAttr *attr;
45 for (attr = ptr->properties; attr; attr = attr->next)
46 if (!strcmp((
const char *)attr->name,
"code"))
47 ptr_code = attr->children;
51 mt,
"Bad attribute '%.80s' for 'subfield'",
58 mt,
"Missing attribute 'code' for 'subfield'" );
61 if (ptr_code->type == XML_TEXT_NODE)
64 strlen((
const char *)ptr_code->content);
69 mt,
"Missing value for 'code' in 'subfield'" );
72 for (p = ptr->children; p ; p = p->next)
73 if (p->type == XML_TEXT_NODE)
74 ctrl_data_len += strlen((
const char *)p->content);
75 ctrl_data_buf = (
char *)
nmem_malloc(nmem, ctrl_data_len+1);
76 strcpy(ctrl_data_buf, (
const char *)ptr_code->content);
77 for (p = ptr->children; p ; p = p->next)
78 if (p->type == XML_TEXT_NODE)
79 strcat(ctrl_data_buf, (
const char *)p->content);
85 mt,
"Expected element 'subfield', got '%.80s'", ptr->name);
94 const char *attribute_name,
97 const char *
name = (
const char *) ptr->name;
98 size_t length = strlen(
name);
103 for (attr = ptr->properties; attr; attr = attr->next)
104 if (!strcmp((
const char *)attr->name, attribute_name))
110 char *res,
int turbo,
int indicator_length)
114 for (i = 1; i <= indicator_length; i++)
116 struct _xmlAttr *attr;
118 yaz_snprintf(attrname,
sizeof attrname,
"%s%d", turbo ?
"i" :
"ind", i);
119 for (attr = ptr->properties; attr; attr = attr->next)
121 if (!strcmp((
const char *)attr->name, attrname) &&
122 attr->children && attr->children->type == XML_TEXT_NODE &&
123 attr->children->content &&
124 strlen((
const char *) attr->children->content) < 5)
126 strcat(res, (
const char *)attr->children->content);
137 for (; ptr; ptr = ptr->next)
139 if (ptr->type == XML_ELEMENT_NODE)
141 if (!strncmp((
const char *) ptr->name,
"s", 1))
145 size_t ctrl_data_len = 0;
146 char *ctrl_data_buf = 0;
151 mt,
"Missing 'code' value for 'subfield'" );
155 ctrl_data_len = strlen((
const char *) tag_value);
157 for (p = ptr->children; p ; p = p->next)
158 if (p->type == XML_TEXT_NODE)
159 ctrl_data_len += strlen((
const char *)p->content);
161 ctrl_data_buf = (
char *)
nmem_malloc(nmem, ctrl_data_len+1);
163 strcpy(ctrl_data_buf, (
const char *) tag_value);
164 for (p = ptr->children; p ; p = p->next)
165 if (p->type == XML_TEXT_NODE)
166 strcat(ctrl_data_buf, (
const char *)p->content);
172 mt,
"Expected element 'subfield', got '%.80s'", ptr->name);
182 int *indicator_length)
184 int identifier_length;
186 int length_data_entry;
188 int length_implementation;
189 const char *leader = 0;
190 const xmlNode *ptr = *ptr_p;
192 for(; ptr; ptr = ptr->next)
193 if (ptr->type == XML_ELEMENT_NODE)
195 if ( !strcmp( (
const char *) ptr->name,
"leader") ||
196 (!strncmp((
const char *) ptr->name,
"l", 1) ))
198 xmlNode *p = ptr->children;
199 for(; p; p = p->next)
200 if (p->type == XML_TEXT_NODE)
201 leader = (
const char *) p->content;
209 leader =
"00000nam a22000000a 4500";
211 if (strlen(leader) != 24)
214 " Must have length of 24 characters", strlen(leader));
223 &length_implementation);
229 int indicator_length)
231 for(; ptr; ptr = ptr->next)
232 if (ptr->type == XML_ELEMENT_NODE)
234 if (!strcmp( (
const char *) ptr->name,
"controlfield"))
236 const xmlNode *ptr_tag = 0;
237 struct _xmlAttr *attr;
238 for (attr = ptr->properties; attr; attr = attr->next)
239 if (!strcmp((
const char *)attr->name,
"tag"))
240 ptr_tag = attr->children;
244 mt,
"Bad attribute '%.80s' for 'controlfield'",
251 mt,
"Missing attribute 'tag' for 'controlfield'" );
256 else if (!strcmp((
const char *) ptr->name,
"datafield"))
259 const xmlNode *ptr_tag = 0;
260 struct _xmlAttr *attr;
263 for (attr = ptr->properties; attr; attr = attr->next)
264 if (!strcmp((
const char *)attr->name,
"tag"))
265 ptr_tag = attr->children;
266 else if (!strncmp((
const char *)attr->name,
"ind", 3))
271 mt,
"Bad attribute '%.80s' for 'datafield'",
277 mt,
"Missing attribute 'tag' for 'datafield'" );
281 indstr, indicator_length);
288 "Expected element controlfield or datafield,"
289 " got %.80s", ptr->name);
298 int indicator_length)
300 for(; ptr; ptr = ptr->next)
301 if (ptr->type == XML_ELEMENT_NODE)
303 if (!strncmp( (
const char *) ptr->name,
"c", 1))
310 mt,
"Missing attribute 'tag' for 'controlfield'" );
315 else if (!strncmp((
const char *) ptr->name,
"d",1))
317 struct _xmlAttr *attr;
320 char *indstr =
nmem_malloc(nmem, indicator_length * 5);
325 mt,
"Missing attribute 'tag' for 'datafield'" );
329 for (attr = ptr->properties; attr; attr = attr->next)
330 if (strlen((
const char *)attr->name) == 2 &&
331 attr->name[0] ==
'i')
336 mt,
"Bad attribute '%.80s' for 'd'", attr->name);
345 "Expected element controlfield or datafield,"
346 " got %.80s", ptr->name);
359 int indicator_length = 0;
363 for(; ptr; ptr = ptr->next)
364 if (ptr->type == XML_ELEMENT_NODE)
366 if (!strcmp((
const char *) ptr->name,
"record"))
371 else if (!strcmp((
const char *) ptr->name,
"r"))
379 mt,
"Unknown element '%.80s' in MARC XML reader",
static int yaz_marc_read_xml_subfields(yaz_marc_t mt, const xmlNode *ptr)
int yaz_marc_read_xml(yaz_marc_t mt, const xmlNode *ptr)
parses MARCXML/MarcXchange/TurboMARC record from xmlNode pointer
static char * element_attribute_value_extract(const xmlNode *ptr, const char *attribute_name, NMEM nmem)
static int yaz_marc_read_xml_fields(yaz_marc_t mt, const xmlNode *ptr, int indicator_length)
static void get_indicator_value(yaz_marc_t mt, const xmlNode *ptr, char *res, int turbo, int indicator_length)
static int yaz_marc_read_turbo_xml_subfields(yaz_marc_t mt, const xmlNode *ptr)
static int yaz_marc_read_xml_leader(yaz_marc_t mt, const xmlNode **ptr_p, int *indicator_length)
static int yaz_marc_read_turbo_xml_fields(yaz_marc_t mt, const xmlNode *ptr, int indicator_length)
void yaz_marc_add_controlfield_xml(yaz_marc_t mt, const xmlNode *ptr_tag, const xmlNode *ptr_data)
adds controlfield to MARC structure using xml Nodes
void yaz_marc_cprintf(yaz_marc_t mt, const char *fmt,...)
adds MARC annotation - printf interface
void yaz_marc_add_subfield(yaz_marc_t mt, const char *code_data, size_t code_data_len)
adds subfield to MARC structure
void yaz_marc_add_datafield_xml(yaz_marc_t mt, const xmlNode *ptr_tag, const char *indicator, size_t indicator_len)
adds datafield to MARC structure using xml Nodes
NMEM yaz_marc_get_nmem(yaz_marc_t mt)
returns memory for MARC handle
void yaz_marc_add_datafield_xml2(yaz_marc_t mt, char *tag_value, char *indicators)
adds datafield to MARC structure using xml Nodes
void yaz_marc_set_leader(yaz_marc_t mt, const char *leader_c, int *indicator_length, int *identifier_length, int *base_address, int *length_data_entry, int *length_starting, int *length_implementation)
sets leader, validates it, and returns important values
void yaz_marc_add_controlfield_xml2(yaz_marc_t mt, char *tag, const xmlNode *ptr_data)
adds controlfield to MARC structure using xml Nodes for data
void yaz_marc_reset(yaz_marc_t mt)
clears memory and MARC record
#define YAZ_MARC_MARCXML
Output format: MARCXML.
#define YAZ_MARC_TURBOMARC
Output format: Turbo MARC Index Data format (XML based).
struct yaz_marc_t_ * yaz_marc_t
a yaz_marc_t handle (private content)
void * nmem_malloc(NMEM n, size_t size)
allocates memory block on NMEM handle
struct nmem_control * NMEM
NMEM handle (an opaque pointer to memory).
char * nmem_text_node_cdata(const xmlNode *ptr_cdata, NMEM nmem)
copies TEXT Libxml2 node data to NMEM
Header for Nibble Memory functions + Libxml2 specific stuff.
char * nmem_strdup(NMEM mem, const char *src)
allocates string on NMEM handle (similar strdup)
void yaz_snprintf(char *buf, size_t size, const char *fmt,...)
Header for config file reading utilities.
Header for WRBUF (growing buffer).
Header for common YAZ utilities.