27 #include <libxml/tree.h>
34 for (; ptr; ptr = ptr->next)
36 if (ptr->type == XML_ELEMENT_NODE)
38 if (!strcmp((
const char *) ptr->name,
"subfield"))
40 size_t ctrl_data_len = 0;
41 char *ctrl_data_buf = 0;
42 const xmlNode *p = 0, *ptr_code = 0;
43 struct _xmlAttr *attr;
44 for (attr = ptr->properties; attr; attr = attr->next)
45 if (!strcmp((
const char *)attr->name,
"code"))
46 ptr_code = attr->children;
50 mt,
"Bad attribute '%.80s' for 'subfield'",
57 mt,
"Missing attribute 'code' for 'subfield'" );
60 if (ptr_code->type == XML_TEXT_NODE)
63 strlen((
const char *)ptr_code->content);
68 mt,
"Missing value for 'code' in 'subfield'" );
71 for (p = ptr->children; p ; p = p->next)
72 if (p->type == XML_TEXT_NODE)
73 ctrl_data_len += strlen((
const char *)p->content);
74 ctrl_data_buf = (
char *)
nmem_malloc(nmem, ctrl_data_len+1);
75 strcpy(ctrl_data_buf, (
const char *)ptr_code->content);
76 for (p = ptr->children; p ; p = p->next)
77 if (p->type == XML_TEXT_NODE)
78 strcat(ctrl_data_buf, (
const char *)p->content);
84 mt,
"Expected element 'subfield', got '%.80s'", ptr->name);
93 const char *attribute_name,
96 const char *
name = (
const char *) ptr->name;
97 size_t length = strlen(
name);
102 for (attr = ptr->properties; attr; attr = attr->next)
103 if (!strcmp((
const char *)attr->name, attribute_name))
109 char *res,
int turbo,
int indicator_length)
113 for (i = 1; i <= indicator_length; i++)
115 struct _xmlAttr *attr;
117 sprintf(attrname,
"%s%d", turbo ?
"i" :
"ind", i);
118 for (attr = ptr->properties; attr; attr = attr->next)
120 if (!strcmp((
const char *)attr->name, attrname) &&
121 attr->children && attr->children->type == XML_TEXT_NODE &&
122 attr->children->content &&
123 strlen((
const char *) attr->children->content) < 5)
125 strcat(res, (
const char *)attr->children->content);
136 for (; ptr; ptr = ptr->next)
138 if (ptr->type == XML_ELEMENT_NODE)
140 if (!strncmp((
const char *) ptr->name,
"s", 1))
144 size_t ctrl_data_len = 0;
145 char *ctrl_data_buf = 0;
150 mt,
"Missing 'code' value for 'subfield'" );
154 ctrl_data_len = strlen((
const char *) tag_value);
156 for (p = ptr->children; p ; p = p->next)
157 if (p->type == XML_TEXT_NODE)
158 ctrl_data_len += strlen((
const char *)p->content);
160 ctrl_data_buf = (
char *)
nmem_malloc(nmem, ctrl_data_len+1);
162 strcpy(ctrl_data_buf, (
const char *) tag_value);
163 for (p = ptr->children; p ; p = p->next)
164 if (p->type == XML_TEXT_NODE)
165 strcat(ctrl_data_buf, (
const char *)p->content);
171 mt,
"Expected element 'subfield', got '%.80s'", ptr->name);
181 int *indicator_length)
183 int identifier_length;
185 int length_data_entry;
187 int length_implementation;
188 const char *leader = 0;
189 const xmlNode *ptr = *ptr_p;
191 for(; ptr; ptr = ptr->next)
192 if (ptr->type == XML_ELEMENT_NODE)
194 if ( !strcmp( (
const char *) ptr->name,
"leader") ||
195 (!strncmp((
const char *) ptr->name,
"l", 1) ))
197 xmlNode *p = ptr->children;
198 for(; p; p = p->next)
199 if (p->type == XML_TEXT_NODE)
200 leader = (
const char *) p->content;
208 leader =
"00000nam a22000000a 4500";
210 if (strlen(leader) != 24)
213 " Must have length of 24 characters", strlen(leader));
222 &length_implementation);
228 int indicator_length)
230 for(; ptr; ptr = ptr->next)
231 if (ptr->type == XML_ELEMENT_NODE)
233 if (!strcmp( (
const char *) ptr->name,
"controlfield"))
235 const xmlNode *ptr_tag = 0;
236 struct _xmlAttr *attr;
237 for (attr = ptr->properties; attr; attr = attr->next)
238 if (!strcmp((
const char *)attr->name,
"tag"))
239 ptr_tag = attr->children;
243 mt,
"Bad attribute '%.80s' for 'controlfield'",
250 mt,
"Missing attribute 'tag' for 'controlfield'" );
255 else if (!strcmp((
const char *) ptr->name,
"datafield"))
258 const xmlNode *ptr_tag = 0;
259 struct _xmlAttr *attr;
262 for (attr = ptr->properties; attr; attr = attr->next)
263 if (!strcmp((
const char *)attr->name,
"tag"))
264 ptr_tag = attr->children;
265 else if (!strncmp((
const char *)attr->name,
"ind", 3))
270 mt,
"Bad attribute '%.80s' for 'datafield'",
276 mt,
"Missing attribute 'tag' for 'datafield'" );
280 indstr, indicator_length);
287 "Expected element controlfield or datafield,"
288 " got %.80s", ptr->name);
297 int indicator_length)
299 for(; ptr; ptr = ptr->next)
300 if (ptr->type == XML_ELEMENT_NODE)
302 if (!strncmp( (
const char *) ptr->name,
"c", 1))
309 mt,
"Missing attribute 'tag' for 'controlfield'" );
314 else if (!strncmp((
const char *) ptr->name,
"d",1))
316 struct _xmlAttr *attr;
319 char *indstr =
nmem_malloc(nmem, indicator_length * 5);
324 mt,
"Missing attribute 'tag' for 'datafield'" );
328 for (attr = ptr->properties; attr; attr = attr->next)
329 if (strlen((
const char *)attr->name) == 2 &&
330 attr->name[0] ==
'i')
335 mt,
"Bad attribute '%.80s' for 'd'", attr->name);
344 "Expected element controlfield or datafield,"
345 " got %.80s", ptr->name);
358 int indicator_length = 0;
362 for(; ptr; ptr = ptr->next)
363 if (ptr->type == XML_ELEMENT_NODE)
365 if (!strcmp((
const char *) ptr->name,
"record"))
370 else if (!strcmp((
const char *) ptr->name,
"r"))
378 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 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)
static char * element_attribute_value_extract(const xmlNode *ptr, const char *attribute_name, NMEM nmem)
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)
void * nmem_malloc(NMEM n, size_t size)
allocates memory block on NMEM handle
Header for Nibble Memory functions + Libxml2 specific stuff.
char * nmem_text_node_cdata(const xmlNode *ptr_cdata, NMEM nmem)
copies TEXT Libxml2 node data to NMEM
char * nmem_strdup(NMEM mem, const char *src)
allocates string on NMEM handle (similar strdup)
the internals of a yaz_marc_t handle
Header for WRBUF (growing buffer)
Header for common YAZ utilities.