libnxml  0.18.3
nxml.h
Go to the documentation of this file.
1 /* nXml - Copyright (C) 2005-2007 bakunin - Andrea Marchesini
2  * <bakunin@autistici.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef __N_XML_H__
20 #define __N_XML_H__
21 
22 #include <curl/curl.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <unistd.h>
27 #include <stdarg.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <errno.h>
31 
32 #define LIBNXML_VERSION_STRING "0.18.3"
33 
34 #define LIBNXML_MAJOR_VERSION 0
35 #define LIBNXML_MINOR_VERSION 18
36 #define LIBNXML_MICRO_VERSION 3
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 typedef struct nxml_t nxml_t;
43 typedef struct nxml_data_t nxml_data_t;
44 typedef struct nxml_attr_t nxml_attr_t;
47 
50 
51 /** This enum describes the error type of libnxml */
52 typedef enum
53 {
54  NXML_OK = 0, /**< No error */
55  NXML_ERR_POSIX, /**< For the correct error, use errno */
56  NXML_ERR_PARSER, /**< Parser error */
57  NXML_ERR_DOWNLOAD, /**< Download error */
58  NXML_ERR_DATA /**< The parameters are incorrect */
59 } nxml_error_t;
60 
61 /** This enum describes the type of data element of libnxml */
62 typedef enum
63 {
64  NXML_TYPE_TEXT, /**< Text element */
65  NXML_TYPE_COMMENT, /**< Comment element */
66  NXML_TYPE_ELEMENT, /**< Data element */
67  NXML_TYPE_PI, /**< PI element */
68  NXML_TYPE_ELEMENT_CLOSE /**< Data element - For internal use only */
69 } nxml_type_t;
70 
71 /** This enum describes the supported XML version */
72 typedef enum
73 {
74  NXML_VERSION_1_1, /**< XML 1.1 */
75  NXML_VERSION_1_0 /**< XML 1.0 */
77 
78 /** This enum describes the CharSet of XML document */
79 typedef enum
80 {
81  NXML_CHARSET_UTF8, /**< UTF8 chatset detected */
82  NXML_CHARSET_UTF16LE, /**< UTF 16 Little Endian detected */
83  NXML_CHARSET_UTF16BE, /**< UTF 16 Big Endian detected */
84  NXML_CHARSET_UCS4_1234, /**< UCS 4byte order 1234 detected */
85  NXML_CHARSET_UCS4_4321, /**< UCS 3byte order 4321 detected */
86  NXML_CHARSET_UCS4_2143, /**< UCS 3byte order 2143 detected */
87  NXML_CHARSET_UCS4_3412, /**< UCS 3byte order 3412 detected */
88  NXML_CHARSET_UNKNOWN /**< Unknown format */
90 
91 /**
92  * Data struct for any element of XML stream/files
93  *
94  * \brief
95  * Data struct for any element of XML streams/files
96  */
98 {
99  nxml_type_t type; /**< type of this nxml_data_t struct */
100 
101  char *value; /**< The value of this data struct */
102 
103  nxml_attr_t *attributes; /**< List of attributes of this struct.
104  This list exists only if
105  type == NXML_TYPE_ELEMENT */
106 
107  nxml_namespace_t *ns; /**< Pointer to the correct namespace */
108  nxml_namespace_t *ns_list; /**< The namespaces in this element */
109 
110  nxml_data_t *children; /**< The children of this data struct */
111  nxml_data_t *next; /**< The next element */
112 
113  nxml_data_t *parent; /**< The parent */
114  nxml_t *doc; /**< The nxml_t */
115 };
116 
117 /**
118  * Data struct for any element of attribute of xml element
119  *
120  * \brief
121  * Data struct for any element of attribute of xml element
122  */
124 {
125  char *name;
126  char *value;
127 
129 
131 };
132 
133 /**
134  * Data struct for doctype elements
135  *
136  * \brief
137  * Data struct for doctype elements
138  */
140 {
141  char *value; /**< The string no parsers */
142  char *name; /**< The name of current doctype */
143 
144  nxml_t *doc; /**< The nxml_t */
146 };
147 
148 /**
149  * Data struct for namespace
150  *
151  * \brief
152  * Data struct for namespace
153  */
155 {
156  char *prefix;
157  char *ns;
159 };
160 
161 /** Data struct private about entities for internal use only
162  *
163  * \brief
164  * Data struct private about entities for internal use only
165  */
167 {
168  char *name;
169  char *entity;
170 
172 };
173 
174 /** Data struct private for internal use only
175  *
176  * \brief
177  * Data struct private for internal use only
178  */
180 {
181  void (*func) (char *, ...);
182  int line;
183  int timeout;
184  char *proxy;
186  char *cacert;
187  char *certfile;
188  char *password;
191  char *user_agent;
193 
194  CURLcode curl_error;
195 
197 };
198 
199 /**
200  * Principal data struct. It describes a XML document and it contains pointers
201  * to any other structures.
202  *
203  * \brief
204  * Principal data struct. It describes a XML document and it contains pointers
205  * to any other structures */
206 struct nxml_t
207 {
208 
209  char *file; /**< XML document filename or url */
210  size_t size; /**< Size of XML document in byte */
211 
212  nxml_version_t version; /**< XML document version */
213  int standalone; /**< This document is standalone ? */
214  char *encoding; /**< Encoding type */
215 
216  nxml_charset_t charset_detected; /**< charset detected when the a
217  XML document is parsed. The document
218  will be convert to UTF-8 */
219 
220  nxml_data_t *data; /**< The data of XML document */
221  nxml_doctype_t *doctype; /**< The doctype of XML document */
222 
223  __nxml_private_t priv; /**< For internal use only */
224 };
225 
226 /* INIT FUNCTIONS ************************************************************/
227 
228 /**
229  * This function creates a new nxml_t data struct.
230  *
231  * \param nxml Pointer to a nxml_t data struct. It will be allocated.
232  * \return the error code
233  */
234 nxml_error_t nxml_new (nxml_t ** nxml);
235 
236 /**
237  * This function creates a new nxml_data_t child of a parent in the data
238  * struct. If parent is NULL the child will be created in the root level
239  * of XML document.
240  *
241  * \param nxml Pointer to a nxml_t data struct.
242  * \param parent The parent of new data struct child. If it is NULL, the
243  * child is in the root level.
244  * \param child It is the pointer to the new data struct. If *child is NULL,
245  * it will be allocated, else it will be insert as it is.
246  * \return the error code
247  *
248  * \code
249  * nxml_data_t *data1, *data2;
250  * data1=NULL;
251  * nxml_add(nxml, NULL, &data1);
252  *
253  * data2=(nxml_data_t *)malloc(sizeof(nxml_data_t));
254  * nxml_add(nxml, NULL, &data2);
255  * \endcode
256  */
257 nxml_error_t nxml_add (nxml_t * nxml,
259  nxml_data_t **child);
260 
261 /**
262  * This function removes a nxml_data_t child from a parent in the data
263  * struct. If parent is NULL the child will be removed in the root level of
264  * XML document. This function doesn't free the child. If you want you can
265  * reinsert the child in another parent tree or use the nxml_free_data
266  * function.
267  *
268  * \param nxml Pointer to a nxml_t data struct.
269  * \param parent The parent of data struct child. If it is NULL, the
270  * child will be searched in the root level.
271  * \param child It is the pointer to the child that you want remove
272  * \return the error code
273  */
274 nxml_error_t nxml_remove (nxml_t * nxml,
276  nxml_data_t *child);
277 
278 /**
279  * This function creates a new nxml_attr_t data of a element in the data
280  * struct.
281  *
282  * \param nxml Pointer to a nxml_t data struct.
283  * \param element The element of the new data struct attribute.
284  * \param attribute The pointer to the your data struct. If it is NULL it will
285  * be allocated, else no.
286  * \return the error code
287  */
288 nxml_error_t nxml_add_attribute (nxml_t *nxml,
289  nxml_data_t *element,
290  nxml_attr_t **attribute);
291 
292 /**
293  * This function removes a nxml_attr_t data of a element. It does not free it
294  * so you can reinsert o free it with nxml_free_attribute.
295  *
296  * \param nxml Pointer to a nxml_t data struct.
297  * \param element The element that contains the attribute
298  * \param attribute The attribute that you want remove.
299  * \return the error code
300  */
301 nxml_error_t nxml_remove_attribute (nxml_t *nxml,
302  nxml_data_t *element,
303  nxml_attr_t *attribute);
304 
305 /**
306  * This function adds a nxml_namespace_t data in a nxml document.
307  *
308  * \param nxml Pointer to a nxml_t data struct.
309  * \param element The element of the new data struct namespace.
310  * \param ns The namespace that you want add
311  * \return the error code
312  */
313 nxml_error_t nxml_add_namespace (nxml_t *nxml,
314  nxml_data_t *element,
315  nxml_namespace_t **ns);
316 
317 /**
318  * This function removes a nxml_namespace_t data from a nxml document.
319  *
320  * \param nxml Pointer to a nxml_t data struct.
321  * \param element The element of the new data struct namespace.
322  * \param ns The namespace that you want remove
323  * \return the error code
324  */
325 nxml_error_t nxml_remove_namespace (nxml_t *nxml,
326  nxml_data_t *element,
328 
329 /**
330  * This function sets the output function. If you set your function, the
331  * parser'll write the error by this function. As default there is not a
332  * function. If you want tou can set 'nxml_print_general' function that
333  * print to stderr.
334  *
335  * \param nxml The struct create with nxml_new.
336  * \param func Your function. If you don't want the function, set it to NULL.
337  * As default a nxml_t element has not a output function.
338  * \return the error code
339  */
340 nxml_error_t nxml_set_func (nxml_t * nxml,
341  void (*func) (char *, ...));
342 
343 void nxml_print_generic (char *, ...);
344 
345 /**
346  * This function sets the timeout in seconds for the download of a remote
347  * XML document. Default is 0 and 0 is no timeout.
348  *
349  * \param nxml The struct create with nxml_new.
350  * \param seconds the timeout in seconds
351  * \return the error code
352  */
353 nxml_error_t nxml_set_timeout (nxml_t * nxml,
354  int seconds);
355 
356 /**
357  * This functions sets a proxy server for the downloading procedure.
358  *
359  * \param nxml The struct create with nxml_new.
360  * \param proxy the proxy as a string
361  * \param userpwd the user and password in this format user:password
362  * \return the error code
363  */
364 nxml_error_t nxml_set_proxy (nxml_t * nxml,
365  char *proxy,
366  char *userpwd);
367 
368 /**
369  * This functions sets a user/password for a for the download procedure.
370  *
371  * \param nxml The struct create with nxml_new.
372  * \param userpwd the user and password in this format user:password
373  * \return the error code
374  */
375 nxml_error_t nxml_set_authentication (nxml_t * nxml,
376  char *userpwd);
377 
378 /**
379  * This functions sets an user agent for a for the download procedure.
380  *
381  * \param nxml The struct create with nxml_new.
382  * \param user_agent The agent
383  * \return the error code
384  */
385 nxml_error_t nxml_set_user_agent (nxml_t * nxml,
386  char *user_agent);
387 
388 /**
389  * This functions sets a certificate in the http request. You can set a
390  * certificate file and a password.
391  *
392  * \param nxml The struct create with nxml_new.
393  * \param certfile the certfile for the ssl connection (can be NULL)
394  * \param password the password of your certifcate (can be NULL)
395  * \param cacert the CA certificate to verify peer against (can be NULL)
396  * \param verifypeer active/deactive the peer validation
397  * \return the error code
398  */
399 nxml_error_t nxml_set_certificate (nxml_t * nxml,
400  char *certfile,
401  char *password,
402  char *cacert,
403  int verifypeer);
404 
405 
406 /**
407  * This function (de)actives the indent of the TEXT elements. Default it is
408  * activated.
409  *
410  * \param nxml The struct create with nxml_new
411  * \param textindent If it is != 0, the indent will be activated
412  * \return the error code
413  */
414 nxml_error_t nxml_set_textindent (nxml_t *nxml,
415  char textindent);
416 
417 /* DOWNLOAD *****************************************************************/
418 
419 /**
420  * This function downloads a stream from a http/https/ftp server.
421  *
422  * \param nxml The struct create with nxml_new.
423  * \param url the http file
424  * \param buffer a string for the buffer
425  * \param size The function sets here the length of the file if it's not NULL.
426  * \return a buffer or NULL
427  */
428 nxml_error_t nxml_download_file (nxml_t *nxml,
429  char *url,
430  char ** buffer,
431  size_t *size);
432 
433 /* PARSER FUNCTIONS *********************************************************/
434 
435 /**
436  * This function parses a url. It downloads a url with curl library and
437  * parses it.
438  *
439  * \param nxml the struct create with nxml_new.
440  * \param url the url that you want parse.
441  * \return the error code
442  */
443 nxml_error_t nxml_parse_url (nxml_t * nxml,
444  char *url);
445 
446 /**
447  * This function parses a file.
448  *
449  * \param nxml the struct create with nxml_new.
450  * \param file the file that you want parse.
451  * \return the error code
452  */
453 nxml_error_t nxml_parse_file (nxml_t * nxml,
454  char *file);
455 
456 /**
457  * This function parses a buffer in memory.
458  *
459  * \param nxml the struct create with nxml_new.
460  * \param buffer the buffer that you want parse.
461  * \param size the size of buffer. If size is 0, the function checks the
462  * length of your buffer searching a '\\0'.
463  * \return the error code
464  */
465 nxml_error_t nxml_parse_buffer (nxml_t * nxml,
466  char *buffer,
467  size_t size);
468 
469 /* WRITE FUNCTIONS **********************************************************/
470 
471 /**
472  * This function writes the data struct in a local file.
473  *
474  * \param nxml the nxml data strut
475  * \param file the local file
476  * \return the error code
477  */
478 nxml_error_t nxml_write_file (nxml_t *nxml,
479  char *file);
480 
481 /**
482  * This function writes the data struct in a buffer.
483  *
484  * \code
485  * char *buffer;
486  * buffer=NULL; // This is important!
487  * nxml_write_buffer(nxml, &buffer);
488  * \endcode
489  *
490  * The buffer must be NULL.
491  *
492  * \param nxml
493  * \param buffer the memory buffer
494  * \return the error code
495  */
496 nxml_error_t nxml_write_buffer (nxml_t *nxml,
497  char **buffer);
498 
499 /* FREE FUNCTIONS ************************************************************/
500 
501 /**
502  * This function removes the data in a structure nxml_t and makes it clean for
503  * another usage.
504  *
505  * \param nxml the pointer to you data struct.
506  * \return the error code.
507  */
508 nxml_error_t nxml_empty (nxml_t * nxml);
509 
510 /**
511  * This function frees the memory of a nxml_t *element. After the free,
512  * your data struct is not useful. If you want erase the internal data, use
513  * nxml_empty function
514  *
515  * \param nxml the pointer to your data struct.
516  * \return the error code.
517  */
518 nxml_error_t nxml_free (nxml_t * nxml);
519 
520 /**
521  * This function frees the memory of a nxml_data_t *element and any its
522  * children and its attributes.
523  *
524  * \param data the pointer to you data struct.
525  * \return the error code
526  */
527 nxml_error_t nxml_free_data (nxml_data_t *data);
528 
529 /**
530  * This function frees the memory of a nxml_attr_t *element.
531  *
532  * \param data the pointer to you data struct.
533  * \return the error code
534  */
535 nxml_error_t nxml_free_attribute (nxml_attr_t *data);
536 
537 /**
538  * This function frees the memory of a nxml_namespace_t *element.
539  *
540  * \param data the pointer to you data struct.
541  * \return the error code
542  */
543 nxml_error_t nxml_free_namespace (nxml_namespace_t *data);
544 
545 /* EDIT FUNCTIONS ***********************************************************/
546 
547 /**
548  * This function returns the root element of xml data struct.
549  *
550  * \code
551  * nxml_t *nxml;
552  * nxml_data_t *root;
553  *
554  * nxml_new(&nxml);
555  * nxml_parser_file(nxml, "file.xml");
556  * nxml_root_element(nxml, &root);
557  * printf("%p\n",root);
558  * nxml_free(nxml);
559  * \endcode
560  *
561  * \param nxml the data struct
562  * \param element the pointer to your nxml_data_t struct
563  * \return the error code
564  */
565 nxml_error_t nxml_root_element (nxml_t *nxml,
566  nxml_data_t **element);
567 
568 /**
569  * This function searchs the request element in the children of the data struct.
570  *
571  * \code
572  * nxml_t *nxml;
573  * nxml_data_t *root;
574  *
575  * nxml_new(&nxml);
576  * nxml_parser_file(nxml, "file.xml");
577  * nxml_find_element(nxml, NULL, "hello_world", &root);
578  * printf("%p\n",root);
579  * nxml_free(nxml);
580  * \endcode
581  *
582  * \param nxml the data struct
583  * \param parent the data struct nxml_data_t of parent. If it is NULL, this
584  * function searchs in the root element level.
585  * \param name the name of the node that you want.
586  * \param element the pointer to your nxml_data_t struct. If element will be
587  * NULL, the item that you want does not exist.
588  * \return the error code
589  */
590 nxml_error_t nxml_find_element (nxml_t *nxml,
592  char *name,
593  nxml_data_t **element);
594 
595 /**
596  * This function searchs the first doctype element in the nxml_t document.
597  *
598  * \param nxml the data struct
599  * \param doctype the pointer to your nxml_doctype_t struct. If element will be
600  * NULL, the item that you want does not exist.
601  * \return the error code
602  */
603 nxml_error_t nxml_doctype_element (nxml_t *nxml,
604  nxml_doctype_t **doctype);
605 
606 /**
607  * This function searchs the request attribute and returns its values.
608  *
609  * \code
610  * nxml_t *nxml;
611  * nxml_data_t *root;
612  *
613  * nxml_new(&nxml);
614  * nxml_parser_file(nxml, "file.xml");
615  * nxml_find_element(nxml, NULL, "hello_world", &root);
616  * if(root) {
617  * nxml_attr_t *attribute=NULL;
618  * nxml_find_attribute(root, "attribute", &attribute);
619  *
620  * if(attribute)
621  * printf("%s\n",attribute->value);
622  * }
623  * nxml_free(nxml);
624  * \endcode
625  *
626  * \param data the data struct
627  * \param name the attribute that you want search
628  * \param attribute the pointer to your nxml_attr_t struct. If attribute will
629  * be NULL, the attribute that you want does not exist.
630  * does not exist.
631  * \return the error code
632  */
633 nxml_error_t nxml_find_attribute (nxml_data_t *data,
634  char *name,
635  nxml_attr_t **attribute);
636 
637 /**
638  * This function searchs the request namespaceibute and returns its values.
639  *
640  * \param data the data struct
641  * \param name the namespace that you want search
642  * \param ns the pointer to your nxml_attr_t struct. If namespace will
643  * be NULL, the namespace that you want does not exist.
644  * does not exist.
645  * \return the error code
646  */
647 nxml_error_t nxml_find_namespace (nxml_data_t *data,
648  char *name,
649  nxml_namespace_t **ns);
650 
651 /**
652  * This function returns the string of a XML element.
653  * \code
654  * nxml_t *nxml;
655  * nxml_data_t *root;
656  * char *str;
657  *
658  * nxml_new(&nxml);
659  * nxml_parser_file(nxml, "file.xml");
660  * nxml_find_element(nxml, NULL, "hello_world", &root);
661  * if(root) {
662  * nxml_get_string(root, &str);
663  * if(str) {
664  * printf("Hello_world item contains: %s\n",str);
665  * free(str);
666  * }
667  * }
668  * nxml_free(nxml);
669  * \endcode
670  *
671  * \param element the xnml_data_t pointer
672  * \param string the pointer to you char *. You must free it after usage.
673  * \return the error code
674  */
675 nxml_error_t nxml_get_string (nxml_data_t *element,
676  char **string);
677 
678 /* ERROR FUNCTIONS **********************************************************/
679 
680 /**
681  * This function returns a static string with the description of error code
682  *
683  * \param nxml the pointer to data struct
684  * \param err the error code that you need as string
685  * \return a string. Don't free this string!
686  */
687 char * nxml_strerror (nxml_t * nxml,
688  nxml_error_t err);
689 
690 /**
691  * This function returns the CURLcode error if there was a problem about the
692  * downloading procedure:
693  *
694  * \param nxml the pointer to data struct
695  * \param err the error code that you need as string
696  * \return the CURLcode
697  */
698 CURLcode nxml_curl_error (nxml_t * nxml,
699  nxml_error_t err);
700 
701 /**
702  * This function return the line of a error of parse.
703  *
704  * \param nxml the pointer to data struct
705  * \param line pointer to your integer. In this pointer will be set the line.
706  * \return the error code
707  */
708 nxml_error_t nxml_line_error (nxml_t * nxml,
709  int *line);
710 
711 /* EASY FUNCTIONS ***********************************************************/
712 
713 /**
714  * This function returns a new nxml_t data.
715  *
716  * \param err If err is not NULL, err will be set to the error flag.
717  * \return the pointer to a new nxml_t data. If it returns NULL, read the err
718  * code. This function use nxml_set_func with nxml_print_generic so the
719  * error will be write in the standard output.
720  */
721 nxml_t * nxmle_new_data (nxml_error_t *err);
722 
723 /**
724  * This function returns a new nxml_t data and parses a remote url document
725  * from http or ftp protocol. This function use nxml_set_func with
726  * nxml_print_generic so the error will be write in the standard output.
727  *
728  * \param url the url that you want parse.
729  * \param err If err is not NULL, err will be set to the error flag.
730  * \return the pointer to a new nxml_t data.
731  */
732 nxml_t * nxmle_new_data_from_url (char *url,
733  nxml_error_t *err);
734 
735 /**
736  * This function returns a new nxml_t data and parses a local file. This
737  * function use nxml_set_func with nxml_print_generic so the error will be
738  * write in the standard output.
739  *
740  * \param file the file that you want parse.
741  * \param err If err is not NULL, err will be set to the error flag.
742  * \return the pointer to a new nxml_t data.
743  */
745  (char *file,
746  nxml_error_t *err);
747 
748 /**
749  * This function returns a new nxml_t data and parses a buffer. This
750  * function use nxml_set_func with nxml_print_generic so the error will be
751  * write in the standard output.
752  *
753  * \param buffer the buffer that you want parse.
754  * \param size the size of buffer. If size is 0, the function checks the
755  * \param err If err is not NULL, err will be set to the error flag.
756  * \return the pointer to a new nxml_t data.
757  */
759  (char *buffer,
760  size_t size,
761  nxml_error_t *err);
762 
763 /**
764  * This function creates and adds a child nxml_data_t to a parent in your
765  * nxml data struct.
766  *
767  * \param nxml Pointer to your nxml data.
768  * \param parent The parent of new data struct child. If it is NULL, the
769  * child is in the root level.
770  * \param err If err is not NULL, err will be set to the error flag.
771  * \return the pointer to a new nxml_data_t data child.
772  */
775  nxml_error_t *err);
776 
777 /**
778  * This function adds a your nxml_data_t to a parent in your nxml
779  * data struct.
780  *
781  * \param nxml Pointer to your nxml data.
782  * \param parent The parent of new data struct child. If it is NULL, the
783  * child is in the root level.
784  * \param child The you child nxml_data_t struct that you want insert.
785  * \param err If err is not NULL, err will be set to the error flag.
786  * \return the pointer to a new nxml_data_t data child.
787  */
790  nxml_data_t *child,
791  nxml_error_t *err);
792 
793 /**
794  * This function creates and adds an attribute nxml_attr_t data to a
795  * nxml_data_t struct in your nxml data struct.
796  *
797  * \param nxml Pointer to your nxml data.
798  * \param element The parent of new nxml_attr_t struct.
799  * \param err If err is not NULL, err will be set to the error flag.
800  * \return the pointer to a new nxml_data_t data child.
801  */
803  nxml_data_t *element,
804  nxml_error_t *err);
805 
806 /**
807  * This function adds an attribute nxml_attr_t data to a
808  * nxml_data_t struct in your nxml data struct.
809  *
810  * \param nxml Pointer to your nxml data.
811  * \param element The parent of your nxml_attr_t struct.
812  * \param attribute Your attribute element.
813  * \param err If err is not NULL, err will be set to the error flag.
814  * \return the pointer to a new nxml_data_t data child.
815  */
817  (nxml_t *nxml,
818  nxml_data_t *element,
819  nxml_attr_t *attribute,
820  nxml_error_t *err);
821 
822 /**
823  * This function creates and adds a namespace nxml_namespace_t data to a
824  * nxml data struct.
825  *
826  * \param nxml Pointer to your nxml data.
827  * \param element The element of in witch you want add the namespace.
828  * \param err If err is not NULL, err will be set to the error flag.
829  * \return the pointer to a new nxml_data_t data child.
830  */
832  (nxml_t *nxml,
833  nxml_data_t *element,
834  nxml_error_t *err);
835 
836 /**
837  * This function adds an namespace nxml_namespace-t data to a nxml data struct.
838  *
839  * \param nxml Pointer to your nxml data.
840  * \param element The element of in witch you want add the namespace.
841  * \param ns Your namespace element.
842  * \param err If err is not NULL, err will be set to the error flag.
843  * \return the pointer to a new nxml_data_t data child.
844  */
846  (nxml_t *nxml,
847  nxml_data_t *element,
849  nxml_error_t *err);
850 
851 /**
852  * This function returns the root element of a nxml_t.
853  *
854  * \param nxml Pointer to your nxml data.
855  * \param err If err is not NULL, err will be set to the error flag.
856  * \return the pointer to the root element. If NULL the element does not
857  * exist.
858  */
860  nxml_error_t *err);
861 
862 /**
863  * This function returns the first doctype element of a nxml_t.
864  *
865  * \param nxml Pointer to your nxml data.
866  * \param err If err is not NULL, err will be set to the error flag.
867  * \return the pointer to the doctype element. If NULL the element does not
868  * exist.
869  */
871  nxml_error_t *err);
872 
873 /**
874  * This function returns the nxml_data_t pointer to a element by
875  * a name.
876  *
877  * \param nxml Pointer to your nxml data.
878  * \param parent Pointer to your nxml_data_t parent. If it is NULL, this
879  * function searchs in a root element level.
880  * \param name The name of element that you want.
881  * \param err If err is not NULL, err will be set to the error flag.
882  * \return the pointer to the root element. If NULL the element does not
883  * exist.
884  */
887  char *name,
888  nxml_error_t *err);
889 
890 /**
891  * This function returns the value of a attribute by a name.
892  *
893  * \param element Pointer to your nxml_data_t.
894  * \param name The name of attribute that you want.
895  * \param err If err is not NULL, err will be set to the error flag.
896  * \return a pointer to a char allocated so you must free it after usage. If
897  * it is NULL, the attribute does not exist.
898  */
899 char * nxmle_find_attribute (nxml_data_t *element,
900  char *name,
901  nxml_error_t *err);
902 
903 /**
904  * This function returns the value of a namespace by a name.
905  *
906  * \param element Pointer to your nxml_data_t.
907  * \param name The name of namespace that you want.
908  * \param err If err is not NULL, err will be set to the error flag.
909  * \return a pointer to a char allocated so you must free it after usage. If
910  * it is NULL, the namespace does not exist.
911  */
912 char * nxmle_find_namespace (nxml_data_t *element,
913  char *name,
914  nxml_error_t *err);
915 
916 /**
917  * This function returns the contain of a element.
918  *
919  * \param element Pointer to your nxml_data_t.
920  * \param err If err is not NULL, err will be set to the error flag.
921  * \return a pointer to a char allocated so you must free it after usage. If
922  * it is NULL, the attribute does not exist.
923  */
924 char * nxmle_get_string (nxml_data_t *element,
925  nxml_error_t *err);
926 
927 /**
928  * This function writes the data struct in a buffer.
929  *
930  * \param nxml
931  * \param err If err is not NULL, err will be set to the error flag.
932  * \return a pointer to a char allocated so you must free it after usage.
933  */
934 char * nxmle_write_buffer (nxml_t *nxml, nxml_error_t *err);
935 
936 /**
937  * This function return the line of a error of parse.
938  * \param nxml the pointer to data struct
939  * \param err If err is not NULL, err will be set to the error flag.
940  * \return the line with the error.
941  */
942 int nxmle_line_error (nxml_t * nxml, nxml_error_t *err);
943 
944 /* Easy functions defined: */
945 #define nxmle_remove nxml_remove
946 #define nxmle_remove_attribute nxml_remove_attribute
947 #define nxmle_remove_namespace nxml_remove_namespace
948 #define nxmle_write_file nxml_write_file
949 
950 #define nxmle_empty nxml_empty
951 #define nxmle_free nxml_free
952 #define nxmle_free_data nxml_free_data
953 #define nxmle_free_attribute nxml_free_attribute
954 
955 #define nxmle_strerror nxml_strerror
956 
957 #ifdef NXML_INTERNAL
958 # include "nxml_internal.h"
959 #endif
960 
961 #ifdef __cplusplus
962 }
963 #endif
964 
965 #endif
966 
967 /* EOF */
nxml_namespace_t * ns
Definition: nxml.h:128
__nxml_private_t priv
Definition: nxml.h:223
int standalone
Definition: nxml.h:213
nxml_error_t nxml_free_data(nxml_data_t *data)
nxml_error_t nxml_set_func(nxml_t *nxml, void(*func)(char *,...))
char * name
Definition: nxml.h:142
int nxmle_line_error(nxml_t *nxml, nxml_error_t *err)
char * user_agent
Definition: nxml.h:191
void nxml_print_generic(char *,...)
nxml_version_t version
Definition: nxml.h:212
nxml_error_t nxml_free_attribute(nxml_attr_t *data)
nxml_error_t nxml_get_string(nxml_data_t *element, char **string)
nxml_namespace_t * next
Definition: nxml.h:158
nxml_type_t
Definition: nxml.h:62
nxml_error_t nxml_line_error(nxml_t *nxml, int *line)
nxml_t * nxmle_new_data_from_buffer(char *buffer, size_t size, nxml_error_t *err)
char * encoding
Definition: nxml.h:214
nxml_t * nxmle_new_data_from_url(char *url, nxml_error_t *err)
nxml_version_t
Definition: nxml.h:72
nxml_data_t * next
Definition: nxml.h:111
nxml_t * doc
Definition: nxml.h:144
nxml_error_t nxml_doctype_element(nxml_t *nxml, nxml_doctype_t **doctype)
nxml_doctype_t * nxmle_doctype_element(nxml_t *nxml, nxml_error_t *err)
Principal data struct. It describes a XML document and it contains pointers to any other structures...
Definition: nxml.h:206
Data struct for any element of XML streams/files.
Definition: nxml.h:97
char * certfile
Definition: nxml.h:187
nxml_error_t nxml_set_certificate(nxml_t *nxml, char *certfile, char *password, char *cacert, int verifypeer)
nxml_doctype_t * next
Definition: nxml.h:145
char * value
Definition: nxml.h:141
char textindent
Definition: nxml.h:192
nxml_data_t * nxmle_add_new(nxml_t *nxml, nxml_data_t *parent, nxml_error_t *err)
nxml_error_t nxml_free(nxml_t *nxml)
nxml_doctype_t * doctype
Definition: nxml.h:221
nxml_error_t nxml_remove_namespace(nxml_t *nxml, nxml_data_t *element, nxml_namespace_t *ns)
nxml_error_t nxml_set_authentication(nxml_t *nxml, char *userpwd)
nxml_error_t nxml_parse_url(nxml_t *nxml, char *url)
nxml_error_t nxml_empty(nxml_t *nxml)
nxml_error_t nxml_set_textindent(nxml_t *nxml, char textindent)
nxml_error_t nxml_parse_buffer(nxml_t *nxml, char *buffer, size_t size)
nxml_t * nxmle_new_data_from_file(char *file, nxml_error_t *err)
nxml_data_t * nxmle_find_element(nxml_t *nxml, nxml_data_t *parent, char *name, nxml_error_t *err)
char * nxml_strerror(nxml_t *nxml, nxml_error_t err)
Data struct for doctype elements.
Definition: nxml.h:139
char * file
Definition: nxml.h:209
nxml_charset_t charset_detected
Definition: nxml.h:216
Data struct private about entities for internal use only.
Definition: nxml.h:166
nxml_namespace_t * ns
Definition: nxml.h:107
nxml_error_t nxml_set_proxy(nxml_t *nxml, char *proxy, char *userpwd)
nxml_error_t nxml_find_attribute(nxml_data_t *data, char *name, nxml_attr_t **attribute)
char * proxy_authentication
Definition: nxml.h:185
__nxml_entity_t * entities
Definition: nxml.h:196
char * nxmle_find_attribute(nxml_data_t *element, char *name, nxml_error_t *err)
nxml_error_t nxml_download_file(nxml_t *nxml, char *url, char **buffer, size_t *size)
nxml_data_t * nxmle_add_data(nxml_t *nxml, nxml_data_t *parent, nxml_data_t *child, nxml_error_t *err)
CURLcode nxml_curl_error(nxml_t *nxml, nxml_error_t err)
nxml_t * doc
Definition: nxml.h:114
char * cacert
Definition: nxml.h:186
nxml_namespace_t * ns_list
Definition: nxml.h:108
nxml_error_t nxml_set_user_agent(nxml_t *nxml, char *user_agent)
nxml_error_t nxml_add(nxml_t *nxml, nxml_data_t *parent, nxml_data_t **child)
char * proxy
Definition: nxml.h:184
char * value
Definition: nxml.h:126
nxml_error_t nxml_find_namespace(nxml_data_t *data, char *name, nxml_namespace_t **ns)
nxml_attr_t * nxmle_add_attribute_new(nxml_t *nxml, nxml_data_t *element, nxml_error_t *err)
nxml_type_t type
Definition: nxml.h:99
nxml_error_t nxml_find_element(nxml_t *nxml, nxml_data_t *parent, char *name, nxml_data_t **element)
Data struct for namespace.
Definition: nxml.h:154
char * nxmle_get_string(nxml_data_t *element, nxml_error_t *err)
nxml_error_t nxml_write_file(nxml_t *nxml, char *file)
Data struct for any element of attribute of xml element.
Definition: nxml.h:123
nxml_error_t nxml_add_attribute(nxml_t *nxml, nxml_data_t *element, nxml_attr_t **attribute)
nxml_error_t nxml_free_namespace(nxml_namespace_t *data)
char * ns
Definition: nxml.h:157
int verifypeer
Definition: nxml.h:189
char * prefix
Definition: nxml.h:156
nxml_data_t * parent
Definition: nxml.h:113
nxml_data_t * children
Definition: nxml.h:110
nxml_error_t nxml_remove_attribute(nxml_t *nxml, nxml_data_t *element, nxml_attr_t *attribute)
size_t size
Definition: nxml.h:210
nxml_namespace_t * nxmle_add_namespace_data(nxml_t *nxml, nxml_data_t *element, nxml_namespace_t *ns, nxml_error_t *err)
nxml_namespace_t * nxmle_add_namespace_new(nxml_t *nxml, nxml_data_t *element, nxml_error_t *err)
nxml_attr_t * nxmle_add_attribute_data(nxml_t *nxml, nxml_data_t *element, nxml_attr_t *attribute, nxml_error_t *err)
nxml_error_t
Definition: nxml.h:52
nxml_data_t * nxmle_root_element(nxml_t *nxml, nxml_error_t *err)
nxml_attr_t * next
Definition: nxml.h:130
nxml_error_t nxml_new(nxml_t **nxml)
nxml_error_t nxml_remove(nxml_t *nxml, nxml_data_t *parent, nxml_data_t *child)
nxml_data_t * data
Definition: nxml.h:220
char * nxmle_write_buffer(nxml_t *nxml, nxml_error_t *err)
CURLcode curl_error
Definition: nxml.h:194
char * name
Definition: nxml.h:125
char * entity
Definition: nxml.h:169
__nxml_entity_t * next
Definition: nxml.h:171
nxml_error_t nxml_set_timeout(nxml_t *nxml, int seconds)
Definition: nxml.h:54
nxml_error_t nxml_add_namespace(nxml_t *nxml, nxml_data_t *element, nxml_namespace_t **ns)
char * name
Definition: nxml.h:168
char * authentication
Definition: nxml.h:190
nxml_t * nxmle_new_data(nxml_error_t *err)
nxml_error_t nxml_parse_file(nxml_t *nxml, char *file)
nxml_attr_t * attributes
Definition: nxml.h:103
nxml_charset_t
Definition: nxml.h:79
char * nxmle_find_namespace(nxml_data_t *element, char *name, nxml_error_t *err)
nxml_error_t nxml_root_element(nxml_t *nxml, nxml_data_t **element)
Data struct private for internal use only.
Definition: nxml.h:179
char * password
Definition: nxml.h:188
nxml_error_t nxml_write_buffer(nxml_t *nxml, char **buffer)
char * value
Definition: nxml.h:101