3 #include <libxml/parser.h>
7 convert (unsigned char *in
, char *encoding
)
10 int ret
,size
,out_size
,temp
;
11 xmlCharEncodingHandlerPtr handler
;
13 size
= (int)strlen(in
)+1;
15 out
= malloc((size_t)out_size
);
18 handler
= xmlFindCharEncodingHandler(encoding
);
27 ret
= handler
->input(out
, &out_size
, in
, &temp
);
28 if (ret
|| temp
-size
+1) {
30 printf("conversion wasn't successful.\n");
32 printf("conversion wasn't successful. converted: %i octets.\n",temp
);
37 out
= realloc(out
,out_size
+1);
38 out
[out_size
]=0; /*null terminating out*/
49 main(int argc
, char **argv
) {
51 unsigned char *content
, *out
;
54 char *encoding
= "ISO-8859-1";
58 printf("Usage: %s content\n", argv
[0]);
64 out
= convert(content
, encoding
);
66 doc
= xmlNewDoc ("1.0");
67 rootnode
= xmlNewDocNode(doc
, NULL
, (const xmlChar
*)"root", out
);
68 xmlDocSetRootElement(doc
, rootnode
);
70 xmlSaveFormatFileEnc("-", doc
, encoding
, 1);