#include <curl/curl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
Go to the source code of this file.
typedef struct __nxml_entity_t __nxml_entity_t |
typedef struct __nxml_private_t __nxml_private_t |
typedef struct nxml_attr_t nxml_attr_t |
typedef struct nxml_data_t nxml_data_t |
typedef struct nxml_doctype_t nxml_doctype_t |
typedef struct nxml_namespace_t nxml_namespace_t |
enum nxml_charset_t |
This enum describes the CharSet of XML document
Definition at line 79 of file nxml.h.
00080 { 00081 NXML_CHARSET_UTF8, /**< UTF8 chatset detected */ 00082 NXML_CHARSET_UTF16LE, /**< UTF 16 Little Endian detected */ 00083 NXML_CHARSET_UTF16BE, /**< UTF 16 Big Endian detected */ 00084 NXML_CHARSET_UCS4_1234, /**< UCS 4byte order 1234 detected */ 00085 NXML_CHARSET_UCS4_4321, /**< UCS 3byte order 4321 detected */ 00086 NXML_CHARSET_UCS4_2143, /**< UCS 3byte order 2143 detected */ 00087 NXML_CHARSET_UCS4_3412, /**< UCS 3byte order 3412 detected */ 00088 NXML_CHARSET_UNKNOWN /**< Unknown format */ 00089 } nxml_charset_t;
enum nxml_error_t |
This enum describes the error type of libnxml
NXML_OK | No error |
NXML_ERR_POSIX | For the correct error, use errno |
NXML_ERR_PARSER | Parser error |
NXML_ERR_DOWNLOAD | Download error |
NXML_ERR_DATA | The parameters are incorrect |
Definition at line 52 of file nxml.h.
00053 { 00054 NXML_OK = 0, /**< No error */ 00055 NXML_ERR_POSIX, /**< For the correct error, use errno */ 00056 NXML_ERR_PARSER, /**< Parser error */ 00057 NXML_ERR_DOWNLOAD, /**< Download error */ 00058 NXML_ERR_DATA /**< The parameters are incorrect */ 00059 } nxml_error_t;
enum nxml_type_t |
This enum describes the type of data element of libnxml
NXML_TYPE_TEXT | Text element |
NXML_TYPE_COMMENT | Comment element |
NXML_TYPE_ELEMENT | Data element |
NXML_TYPE_PI | PI element |
NXML_TYPE_ELEMENT_CLOSE | Data element - For internal use only |
Definition at line 62 of file nxml.h.
00063 { 00064 NXML_TYPE_TEXT, /**< Text element */ 00065 NXML_TYPE_COMMENT, /**< Comment element */ 00066 NXML_TYPE_ELEMENT, /**< Data element */ 00067 NXML_TYPE_PI, /**< PI element */ 00068 NXML_TYPE_ELEMENT_CLOSE /**< Data element - For internal use only */ 00069 } nxml_type_t;
enum nxml_version_t |
This enum describes the supported XML version
Definition at line 72 of file nxml.h.
00073 { 00074 NXML_VERSION_1_1, /**< XML 1.1 */ 00075 NXML_VERSION_1_0 /**< XML 1.0 */ 00076 } nxml_version_t;
nxml_error_t nxml_add | ( | nxml_t * | nxml, | |
nxml_data_t * | parent, | |||
nxml_data_t ** | child | |||
) |
This function creates a new nxml_data_t child of a parent in the data struct. If parent is NULL the child will be created in the root level of XML document.
nxml | Pointer to a nxml_t data struct. | |
parent | The parent of new data struct child. If it is NULL, the child is in the root level. | |
child | It is the pointer to the new data struct. If *child is NULL, it will be allocated, else it will be insert as it is. |
nxml_data_t *data1, *data2; data1=NULL; nxml_add(nxml, NULL, &data1); data2=(nxml_data_t *)malloc(sizeof(nxml_data_t)); nxml_add(nxml, NULL, &data2);
nxml_error_t nxml_add_attribute | ( | nxml_t * | nxml, | |
nxml_data_t * | element, | |||
nxml_attr_t ** | attribute | |||
) |
This function creates a new nxml_attr_t data of a element in the data struct.
nxml | Pointer to a nxml_t data struct. | |
element | The element of the new data struct attribute. | |
attribute | The pointer to the your data struct. If it is NULL it will be allocated, else no. |
nxml_error_t nxml_add_namespace | ( | nxml_t * | nxml, | |
nxml_data_t * | element, | |||
nxml_namespace_t ** | ns | |||
) |
This function adds a nxml_namespace_t data in a nxml document.
nxml | Pointer to a nxml_t data struct. | |
element | The element of the new data struct namespace. | |
ns | The namespace that you want add |
CURLcode nxml_curl_error | ( | nxml_t * | nxml, | |
nxml_error_t | err | |||
) |
This function returns the CURLcode error if there was a problem about the downloading procedure:
nxml | the pointer to data struct | |
err | the error code that you need as string |
nxml_error_t nxml_doctype_element | ( | nxml_t * | nxml, | |
nxml_doctype_t ** | doctype | |||
) |
This function searchs the first doctype element in the nxml_t document.
nxml | the data struct | |
doctype | the pointer to your nxml_doctype_t struct. If element will be NULL, the item that you want does not exist. |
nxml_error_t nxml_download_file | ( | nxml_t * | nxml, | |
char * | url, | |||
char ** | buffer, | |||
size_t * | size | |||
) |
This function downloads a stream from a http/https/ftp server.
nxml | The struct create with nxml_new. | |
url | the http file | |
buffer | a string for the buffer | |
size | The function sets here the length of the file if it's not NULL. |
nxml_error_t nxml_empty | ( | nxml_t * | nxml | ) |
This function removes the data in a structure nxml_t and makes it clean for another usage.
nxml | the pointer to you data struct. |
nxml_error_t nxml_find_attribute | ( | nxml_data_t * | data, | |
char * | name, | |||
nxml_attr_t ** | attribute | |||
) |
This function searchs the request attribute and returns its values.
nxml_t *nxml; nxml_data_t *root; nxml_new(&nxml); nxml_parser_file(nxml, "file.xml"); nxml_find_element(nxml, NULL, "hello_world", &root); if(root) { nxml_attr_t *attribute=NULL; nxml_find_attribute(root, "attribute", &attribute); if(attribute) printf("%s\n",attribute->value); } nxml_free(nxml);
data | the data struct | |
name | the attribute that you want search | |
attribute | the pointer to your nxml_attr_t struct. If attribute will be NULL, the attribute that you want does not exist. does not exist. |
nxml_error_t nxml_find_element | ( | nxml_t * | nxml, | |
nxml_data_t * | parent, | |||
char * | name, | |||
nxml_data_t ** | element | |||
) |
This function searchs the request element in the children of the data struct.
nxml_t *nxml; nxml_data_t *root; nxml_new(&nxml); nxml_parser_file(nxml, "file.xml"); nxml_find_element(nxml, NULL, "hello_world", &root); printf("%p\n",root); nxml_free(nxml);
nxml | the data struct | |
parent | the data struct nxml_data_t of parent. If it is NULL, this function searchs in the root element level. | |
name | the name of the node that you want. | |
element | the pointer to your nxml_data_t struct. If element will be NULL, the item that you want does not exist. |
nxml_error_t nxml_find_namespace | ( | nxml_data_t * | data, | |
char * | name, | |||
nxml_namespace_t ** | ns | |||
) |
This function searchs the request namespaceibute and returns its values.
data | the data struct | |
name | the namespace that you want search | |
ns | the pointer to your nxml_attr_t struct. If namespace will be NULL, the namespace that you want does not exist. does not exist. |
nxml_error_t nxml_free | ( | nxml_t * | nxml | ) |
This function frees the memory of a nxml_t *element. After the free, your data struct is not useful. If you want erase the internal data, use nxml_empty function
nxml | the pointer to your data struct. |
nxml_error_t nxml_free_attribute | ( | nxml_attr_t * | data | ) |
This function frees the memory of a nxml_attr_t *element.
data | the pointer to you data struct. |
nxml_error_t nxml_free_data | ( | nxml_data_t * | data | ) |
This function frees the memory of a nxml_data_t *element and any its children and its attributes.
data | the pointer to you data struct. |
nxml_error_t nxml_free_namespace | ( | nxml_namespace_t * | data | ) |
This function frees the memory of a nxml_namespace_t *element.
data | the pointer to you data struct. |
nxml_error_t nxml_get_string | ( | nxml_data_t * | element, | |
char ** | string | |||
) |
This function returns the string of a XML element.
nxml_t *nxml; nxml_data_t *root; char *str; nxml_new(&nxml); nxml_parser_file(nxml, "file.xml"); nxml_find_element(nxml, NULL, "hello_world", &root); if(root) { nxml_get_string(root, &str); if(str) { printf("Hello_world item contains: %s\n",str); free(str); } } nxml_free(nxml);
element | the xnml_data_t pointer | |
string | the pointer to you char *. You must free it after usage. |
nxml_error_t nxml_line_error | ( | nxml_t * | nxml, | |
int * | line | |||
) |
This function return the line of a error of parse.
nxml | the pointer to data struct | |
line | pointer to your integer. In this pointer will be set the line. |
nxml_error_t nxml_new | ( | nxml_t ** | nxml | ) |
nxml_error_t nxml_parse_buffer | ( | nxml_t * | nxml, | |
char * | buffer, | |||
size_t | size | |||
) |
This function parses a buffer in memory.
nxml | the struct create with nxml_new. | |
buffer | the buffer that you want parse. | |
size | the size of buffer. If size is 0, the function checks the length of your buffer searching a '\0'. |
nxml_error_t nxml_parse_file | ( | nxml_t * | nxml, | |
char * | file | |||
) |
This function parses a file.
nxml | the struct create with nxml_new. | |
file | the file that you want parse. |
nxml_error_t nxml_parse_url | ( | nxml_t * | nxml, | |
char * | url | |||
) |
This function parses a url. It downloads a url with curl library and parses it.
nxml | the struct create with nxml_new. | |
url | the url that you want parse. |
void nxml_print_generic | ( | char * | , | |
... | ||||
) |
nxml_error_t nxml_remove | ( | nxml_t * | nxml, | |
nxml_data_t * | parent, | |||
nxml_data_t * | child | |||
) |
This function removes a nxml_data_t child from a parent in the data struct. If parent is NULL the child will be removed in the root level of XML document. This function doesn't free the child. If you want you can reinsert the child in another parent tree or use the nxml_free_data function.
nxml | Pointer to a nxml_t data struct. | |
parent | The parent of data struct child. If it is NULL, the child will be searched in the root level. | |
child | It is the pointer to the child that you want remove |
nxml_error_t nxml_remove_attribute | ( | nxml_t * | nxml, | |
nxml_data_t * | element, | |||
nxml_attr_t * | attribute | |||
) |
This function removes a nxml_attr_t data of a element. It does not free it so you can reinsert o free it with nxml_free_attribute.
nxml | Pointer to a nxml_t data struct. | |
element | The element that contains the attribute | |
attribute | The attribute that you want remove. |
nxml_error_t nxml_remove_namespace | ( | nxml_t * | nxml, | |
nxml_data_t * | element, | |||
nxml_namespace_t * | ns | |||
) |
This function removes a nxml_namespace_t data from a nxml document.
nxml | Pointer to a nxml_t data struct. | |
element | The element of the new data struct namespace. | |
ns | The namespace that you want remove |
nxml_error_t nxml_root_element | ( | nxml_t * | nxml, | |
nxml_data_t ** | element | |||
) |
This function returns the root element of xml data struct.
nxml_t *nxml; nxml_data_t *root; nxml_new(&nxml); nxml_parser_file(nxml, "file.xml"); nxml_root_element(nxml, &root); printf("%p\n",root); nxml_free(nxml);
nxml | the data struct | |
element | the pointer to your nxml_data_t struct |
nxml_error_t nxml_set_authentication | ( | nxml_t * | nxml, | |
char * | userpwd | |||
) |
This functions sets a user/password for a for the download procedure.
nxml | The struct create with nxml_new. | |
userpwd | the user and password in this format user:password |
nxml_error_t nxml_set_certificate | ( | nxml_t * | nxml, | |
char * | certfile, | |||
char * | password, | |||
char * | cacert, | |||
int | verifypeer | |||
) |
This functions sets a certificate in the http request. You can set a certificate file and a password.
nxml | The struct create with nxml_new. | |
certfile | the certfile for the ssl connection (can be NULL) | |
password | the password of your certifcate (can be NULL) | |
cacert | the CA certificate to verify peer against (can be NULL) | |
verifypeer | active/deactive the peer validation |
nxml_error_t nxml_set_func | ( | nxml_t * | nxml, | |
void(*)(char *,...) | func | |||
) |
This function sets the output function. If you set your function, the parser'll write the error by this function. As default there is not a function. If you want tou can set 'nxml_print_general' function that print to stderr.
nxml | The struct create with nxml_new. | |
func | Your function. If you don't want the function, set it to NULL. As default a nxml_t element has not a output function. |
nxml_error_t nxml_set_proxy | ( | nxml_t * | nxml, | |
char * | proxy, | |||
char * | userpwd | |||
) |
This functions sets a proxy server for the downloading procedure.
nxml | The struct create with nxml_new. | |
proxy | the proxy as a string | |
userpwd | the user and password in this format user:password |
nxml_error_t nxml_set_textindent | ( | nxml_t * | nxml, | |
char | textindent | |||
) |
This function (de)actives the indent of the TEXT elements. Default it is activated.
nxml | The struct create with nxml_new | |
textindent | If it is != 0, the indent will be activated |
nxml_error_t nxml_set_timeout | ( | nxml_t * | nxml, | |
int | seconds | |||
) |
This function sets the timeout in seconds for the download of a remote XML document. Default is 0 and 0 is no timeout.
nxml | The struct create with nxml_new. | |
seconds | the timeout in seconds |
nxml_error_t nxml_set_user_agent | ( | nxml_t * | nxml, | |
char * | user_agent | |||
) |
This functions sets an user agent for a for the download procedure.
nxml | The struct create with nxml_new. | |
user_agent | The agent |
char* nxml_strerror | ( | nxml_t * | nxml, | |
nxml_error_t | err | |||
) |
This function returns a static string with the description of error code
nxml | the pointer to data struct | |
err | the error code that you need as string |
nxml_error_t nxml_write_buffer | ( | nxml_t * | nxml, | |
char ** | buffer | |||
) |
This function writes the data struct in a buffer.
char *buffer; buffer=NULL; // This is important! nxml_write_buffer(nxml, &buffer);
The buffer must be NULL.
nxml | ||
buffer | the memory buffer |
nxml_error_t nxml_write_file | ( | nxml_t * | nxml, | |
char * | file | |||
) |
This function writes the data struct in a local file.
nxml | the nxml data strut | |
file | the local file |
nxml_attr_t* nxmle_add_attribute_data | ( | nxml_t * | nxml, | |
nxml_data_t * | element, | |||
nxml_attr_t * | attribute, | |||
nxml_error_t * | err | |||
) |
This function adds an attribute nxml_attr_t data to a nxml_data_t struct in your nxml data struct.
nxml | Pointer to your nxml data. | |
element | The parent of your nxml_attr_t struct. | |
attribute | Your attribute element. | |
err | If err is not NULL, err will be set to the error flag. |
nxml_attr_t* nxmle_add_attribute_new | ( | nxml_t * | nxml, | |
nxml_data_t * | element, | |||
nxml_error_t * | err | |||
) |
This function creates and adds an attribute nxml_attr_t data to a nxml_data_t struct in your nxml data struct.
nxml | Pointer to your nxml data. | |
element | The parent of new nxml_attr_t struct. | |
err | If err is not NULL, err will be set to the error flag. |
nxml_data_t* nxmle_add_data | ( | nxml_t * | nxml, | |
nxml_data_t * | parent, | |||
nxml_data_t * | child, | |||
nxml_error_t * | err | |||
) |
This function adds a your nxml_data_t to a parent in your nxml data struct.
nxml | Pointer to your nxml data. | |
parent | The parent of new data struct child. If it is NULL, the child is in the root level. | |
child | The you child nxml_data_t struct that you want insert. | |
err | If err is not NULL, err will be set to the error flag. |
nxml_namespace_t* nxmle_add_namespace_data | ( | nxml_t * | nxml, | |
nxml_data_t * | element, | |||
nxml_namespace_t * | ns, | |||
nxml_error_t * | err | |||
) |
This function adds an namespace nxml_namespace-t data to a nxml data struct.
nxml | Pointer to your nxml data. | |
element | The element of in witch you want add the namespace. | |
ns | Your namespace element. | |
err | If err is not NULL, err will be set to the error flag. |
nxml_namespace_t* nxmle_add_namespace_new | ( | nxml_t * | nxml, | |
nxml_data_t * | element, | |||
nxml_error_t * | err | |||
) |
This function creates and adds a namespace nxml_namespace_t data to a nxml data struct.
nxml | Pointer to your nxml data. | |
element | The element of in witch you want add the namespace. | |
err | If err is not NULL, err will be set to the error flag. |
nxml_data_t* nxmle_add_new | ( | nxml_t * | nxml, | |
nxml_data_t * | parent, | |||
nxml_error_t * | err | |||
) |
This function creates and adds a child nxml_data_t to a parent in your nxml data struct.
nxml | Pointer to your nxml data. | |
parent | The parent of new data struct child. If it is NULL, the child is in the root level. | |
err | If err is not NULL, err will be set to the error flag. |
nxml_doctype_t* nxmle_doctype_element | ( | nxml_t * | nxml, | |
nxml_error_t * | err | |||
) |
This function returns the first doctype element of a nxml_t.
nxml | Pointer to your nxml data. | |
err | If err is not NULL, err will be set to the error flag. |
char* nxmle_find_attribute | ( | nxml_data_t * | element, | |
char * | name, | |||
nxml_error_t * | err | |||
) |
This function returns the value of a attribute by a name.
element | Pointer to your nxml_data_t. | |
name | The name of attribute that you want. | |
err | If err is not NULL, err will be set to the error flag. |
nxml_data_t* nxmle_find_element | ( | nxml_t * | nxml, | |
nxml_data_t * | parent, | |||
char * | name, | |||
nxml_error_t * | err | |||
) |
This function returns the nxml_data_t pointer to a element by a name.
nxml | Pointer to your nxml data. | |
parent | Pointer to your nxml_data_t parent. If it is NULL, this function searchs in a root element level. | |
name | The name of element that you want. | |
err | If err is not NULL, err will be set to the error flag. |
char* nxmle_find_namespace | ( | nxml_data_t * | element, | |
char * | name, | |||
nxml_error_t * | err | |||
) |
This function returns the value of a namespace by a name.
element | Pointer to your nxml_data_t. | |
name | The name of namespace that you want. | |
err | If err is not NULL, err will be set to the error flag. |
char* nxmle_get_string | ( | nxml_data_t * | element, | |
nxml_error_t * | err | |||
) |
This function returns the contain of a element.
element | Pointer to your nxml_data_t. | |
err | If err is not NULL, err will be set to the error flag. |
int nxmle_line_error | ( | nxml_t * | nxml, | |
nxml_error_t * | err | |||
) |
This function return the line of a error of parse.
nxml | the pointer to data struct | |
err | If err is not NULL, err will be set to the error flag. |
nxml_t* nxmle_new_data | ( | nxml_error_t * | err | ) |
nxml_t* nxmle_new_data_from_buffer | ( | char * | buffer, | |
size_t | size, | |||
nxml_error_t * | err | |||
) |
This function returns a new nxml_t data and parses a buffer. This function use nxml_set_func with nxml_print_generic so the error will be write in the standard output.
buffer | the buffer that you want parse. | |
size | the size of buffer. If size is 0, the function checks the | |
err | If err is not NULL, err will be set to the error flag. |
nxml_t* nxmle_new_data_from_file | ( | char * | file, | |
nxml_error_t * | err | |||
) |
This function returns a new nxml_t data and parses a local file. This function use nxml_set_func with nxml_print_generic so the error will be write in the standard output.
file | the file that you want parse. | |
err | If err is not NULL, err will be set to the error flag. |
nxml_t* nxmle_new_data_from_url | ( | char * | url, | |
nxml_error_t * | err | |||
) |
This function returns a new nxml_t data and parses a remote url document from http or ftp protocol. This function use nxml_set_func with nxml_print_generic so the error will be write in the standard output.
url | the url that you want parse. | |
err | If err is not NULL, err will be set to the error flag. |
nxml_data_t* nxmle_root_element | ( | nxml_t * | nxml, | |
nxml_error_t * | err | |||
) |
This function returns the root element of a nxml_t.
nxml | Pointer to your nxml data. | |
err | If err is not NULL, err will be set to the error flag. |
char* nxmle_write_buffer | ( | nxml_t * | nxml, | |
nxml_error_t * | err | |||
) |
This function writes the data struct in a buffer.
nxml | ||
err | If err is not NULL, err will be set to the error flag. |