YAZ 5.37.0
nmem_xml.c
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
4 */
5
10
11#if HAVE_CONFIG_H
12#include <config.h>
13#endif
14
15#include <string.h>
16#include <yaz/nmem_xml.h>
17
18#if YAZ_HAVE_XML2
19char *nmem_text_node_cdata(const xmlNode *ptr_cdata, NMEM nmem)
20{
21 char *cdata;
22 int len = 0;
23 const xmlNode *ptr;
24
25 for (ptr = ptr_cdata; ptr; ptr = ptr->next)
26 if (ptr->type == XML_TEXT_NODE)
27 len += xmlStrlen(ptr->content);
28 cdata = (char *) nmem_malloc(nmem, len+1);
29 *cdata = '\0';
30 for (ptr = ptr_cdata; ptr; ptr = ptr->next)
31 if (ptr->type == XML_TEXT_NODE)
32 strcat(cdata, (const char *) ptr->content);
33 return cdata;
34}
35
36char *nmem_from_xml_buffer(NMEM nmem, const xmlBufferPtr buf, int *ret_len)
37{
38 int len = xmlBufferLength(buf);
39 if (ret_len)
40 *ret_len = len;
41 return nmem_strdupn(nmem, (const char *) xmlBufferContent(buf), len);
42}
43#endif
44
45/*
46 * Local variables:
47 * c-basic-offset: 4
48 * c-file-style: "Stroustrup"
49 * indent-tabs-mode: nil
50 * End:
51 * vim: shiftwidth=4 tabstop=8 expandtab
52 */
53
void * nmem_malloc(NMEM n, size_t size)
allocates memory block on NMEM handle
Definition nmem.c:145
struct nmem_control * NMEM
NMEM handle (an opaque pointer to memory).
Definition nmem.h:44
char * nmem_from_xml_buffer(NMEM nmem, const xmlBufferPtr buf, int *ret_len)
copies xmlBuffer data to NMEM
Definition nmem_xml.c:36
char * nmem_text_node_cdata(const xmlNode *ptr_cdata, NMEM nmem)
copies TEXT Libxml2 node data to NMEM
Definition nmem_xml.c:19
Header for Nibble Memory functions + Libxml2 specific stuff.
char * nmem_strdupn(NMEM mem, const char *src, size_t n)
allocates string of certain size on NMEM handle
Definition nmemsdup.c:34