VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.30/doc/tutorial/includeconvert.c@ 20364

最後變更 在這個檔案從20364是 6076,由 vboxsync 提交於 17 年 前

Merged dmik/s2 branch (r25959:26751) to the trunk.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Date Revision Author Id
檔案大小: 1.8 KB
 
1<![CDATA[
2#include <string.h>
3#include <libxml/parser.h>
4
5
6unsigned char*
7convert (unsigned char *in, char *encoding)
8{
9 unsigned char *out;
10 int ret,size,out_size,temp;
11 xmlCharEncodingHandlerPtr handler;
12
13 size = (int)strlen(in)+1;
14 out_size = size*2-1;
15 out = malloc((size_t)out_size);
16
17 if (out) {
18 handler = xmlFindCharEncodingHandler(encoding);
19
20 if (!handler) {
21 free(out);
22 out = NULL;
23 }
24 }
25 if (out) {
26 temp=size-1;
27 ret = handler->input(out, &out_size, in, &temp);
28 if (ret || temp-size+1) {
29 if (ret) {
30 printf("conversion wasn't successful.\n");
31 } else {
32 printf("conversion wasn't successful. converted: %i octets.\n",temp);
33 }
34 free(out);
35 out = NULL;
36 } else {
37 out = realloc(out,out_size+1);
38 out[out_size]=0; /*null terminating out*/
39
40 }
41 } else {
42 printf("no mem\n");
43 }
44 return (out);
45}
46
47
48int
49main(int argc, char **argv) {
50
51 unsigned char *content, *out;
52 xmlDocPtr doc;
53 xmlNodePtr rootnode;
54 char *encoding = "ISO-8859-1";
55
56
57 if (argc <= 1) {
58 printf("Usage: %s content\n", argv[0]);
59 return(0);
60 }
61
62 content = argv[1];
63
64 out = convert(content, encoding);
65
66 doc = xmlNewDoc ("1.0");
67 rootnode = xmlNewDocNode(doc, NULL, (const xmlChar*)"root", out);
68 xmlDocSetRootElement(doc, rootnode);
69
70 xmlSaveFormatFileEnc("-", doc, encoding, 1);
71 return (1);
72}
73]]>
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette