/* Build like so: * gcc test_writes_invalid.c `pkg-config gio-2.0 libxml-2.0 --cflags --libs` * * then try: * xmllint --nooout ./output.txt to see: * to see: * ./output.xml:4: parser error : PCDATA invalid Char value 12 */ #include #include #include int main(int argc, char** argv) { g_type_init (); xmlDocPtr document = xmlNewDoc(BAD_CAST "1.0"); xmlNodePtr root_node = xmlNewNode(NULL, BAD_CAST "root"); xmlDocSetRootElement(document, root_node); GFile* file = g_file_new_for_path("./input.txt"); char* contents = 0; gsize length = 0; if(!g_file_load_contents(file, 0, &contents, &length, NULL, NULL)) { g_warning("g_file_load_contents() failed"); return -1; } xmlNodePtr child_node = xmlNewText(BAD_CAST contents); xmlAddChild(root_node, child_node); g_free(contents); xmlSaveFormatFileEnc("output.xml", document, "UTF-8", 1); return 0; }