Here is a simple test case that takes the text from an apparently-valid UTF-8 file, puts it in a text child node, and then writes the XML file out. But the XML file fails validation with xmllint with this error: ./output.xml:4: parser error : PCDATA invalid Char value 12
Am I doing something wrong? -- murr...@murrayc.com www.murrayc.com www.openismus.com
The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
/* 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 <libxml/parser.h> #include <libxml/tree.h> #include <gio/gio.h> 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; }
_______________________________________________ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org http://mail.gnome.org/mailman/listinfo/xml