1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/* nXml - Copyright (C) 2005-2021 baku - Andrea Marchesini
* <baku@ippolita.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "nxml.h"
void check(nxml_t *data, nxml_error_t err) {
puts(nxmle_strerror(data, err));
if (err != NXML_OK)
exit(1);
}
int main(int argc, char **argv) {
nxml_t *data;
nxml_data_t *element, *text;
nxml_attr_t *attribute;
nxml_error_t err;
char *buffer;
fprintf(stdout, "New data... ");
data = nxmle_new_data(&err);
check(data, err);
fprintf(stdout, "Freeing memory... ");
err = nxmle_free(data);
check(data, err);
fprintf(stdout, "** (Debian) Skipping tests using internet... ");
return 0;
fprintf(stdout, "New data from url... ");
data = nxmle_new_data_from_url("http://www.autistici.org/bakunin/index.php",
&err);
check(data, err);
buffer = NULL;
fprintf(stdout, "Writing in a buffer... ");
buffer = nxmle_write_buffer(data, &err);
check(data, err);
fprintf(stdout, "Freeing memory... ");
err = nxmle_free(data);
check(data, err);
fprintf(stdout, "New data from buffer... ");
data = nxmle_new_data_from_buffer(buffer, 0, &err);
check(data, err);
free(buffer);
fprintf(stdout, "Writing to file... ");
err = nxmle_write_file(data, "TEST");
check(data, err);
fprintf(stdout, "Freeing memory... ");
err = nxmle_free(data);
check(data, err);
fprintf(stdout, "New data from file... ");
data = nxmle_new_data_from_file("TEST", &err);
check(data, err);
unlink("TEST");
fprintf(stdout, "New nxml_data_t element... ");
element = nxmle_add_new(data, NULL, &err);
check(data, err);
fprintf(stdout, "Removing nxml_data_t element... ");
err = nxmle_remove(data, NULL, element);
check(data, err);
fprintf(stdout, "Re-insert nxml_data_t element... ");
element = nxmle_add_data(data, NULL, element, &err);
check(data, err);
element->value = strdup("hello_world");
element->type = NXML_TYPE_ELEMENT;
fprintf(stdout, "Adding attribute to element... ");
attribute = nxmle_add_attribute_new(data, element, &err);
check(data, err);
attribute->name = strdup("hello");
attribute->value = strdup("world");
fprintf(stdout, "Removing attribute to element... ");
err = nxmle_remove_attribute(data, element, attribute);
check(data, err);
fprintf(stdout, "Re-insert a attribute to element... ");
attribute = nxmle_add_attribute_data(data, element, attribute, &err);
check(data, err);
fprintf(stdout, "Searching the root element... ");
element = nxmle_root_element(data, &err);
check(data, err);
printf("ROOT element: %s\n", element->value);
fprintf(stdout, "Removing the root element element... ");
err = nxmle_remove(data, NULL, element);
nxml_free_data(element);
check(data, err);
fprintf(stdout, "Searching the 'hello_world' element... ");
element = nxmle_find_element(data, NULL, "hello_world", &err);
check(data, err);
printf("Founded element: %s\n", element->value);
fprintf(stdout, "Searching attribute 'hello' in the root element... ");
buffer = nxmle_find_attribute(element, "hello", &err);
check(data, err);
printf("Value: %s\n", buffer);
free(buffer);
fprintf(stdout, "New nxml_data_t element... ");
text = nxmle_add_new(data, element, &err);
check(data, err);
text->value = strdup("bla bla bla...");
text->type = NXML_TYPE_TEXT;
fprintf(stdout, "Getting string in the root element... ");
buffer = nxmle_get_string(element, &err);
check(data, err);
printf("Value: %s\n", buffer);
free(buffer);
nxml_free(data);
return 0;
}
|