Exemple #1
0
xml2::~xml2()
{
	if (iter_)
		acl_myfree(iter_);
	delete root_;
	acl_xml2_free(xml_);
}
Exemple #2
0
static int parse_xml_file(const char *filepath)
{
	int   n;
	acl_int64 len;
	char  buf[10240];
	ACL_VSTREAM *in = acl_vstream_fopen(filepath, O_RDONLY, 0600, 8192);
	const char* outfile = "./out.xml";
	ACL_VSTREAM *out = acl_vstream_fopen(outfile, O_RDWR | O_CREAT | O_TRUNC, 0600, 8192);
	ACL_XML2 *xml;
	const char *mmap_file = "./local.map";
	const char* ptr;

	if (in == NULL) {
		printf("open %s error %s\r\n", filepath, acl_last_serror());
		return -1;
	}

	if (out == NULL)
	{
		printf("open %s error %s\r\n", outfile, acl_last_serror());
		acl_vstream_close(in);
		return -1;
	}

	len = acl_vstream_fsize(in);
	if (len <= 0) {
		printf("fsize %s error %s\r\n", filepath, acl_last_serror());
		acl_vstream_close(in);
		acl_vstream_close(out);
		return -1;
	}

	acl_vstream_printf(">>>file(%s)'s size: %lld\r\n", filepath, len);

	len *= 4;

	xml = acl_xml2_mmap_file(mmap_file, len, 10, 1, NULL);

	len = 0;
	while (1) {
		n = acl_vstream_read(in, buf, sizeof(buf) - 1);
		if (n == ACL_VSTREAM_EOF)
			break;
		buf[n] = 0;
		acl_xml2_update(xml, buf);
		len += n;
	}

	acl_vstream_close(in);

	acl_vstream_printf(">>read size: %lld\r\n", len);

	ptr = acl_xml2_build(xml);
	if (ptr == NULL)
		printf("acl_xml2_build error\r\n");

	len = xml->ptr - ptr;
	acl_vstream_printf(">>>build xml's size:%lld\r\n", len);
	acl_vstream_printf(">>> ptr: {%s}\r\n", ptr);

	if (acl_vstream_writen(out, ptr, len) == ACL_VSTREAM_EOF) {
		printf("write error %s, len: %ld\r\n",
			acl_last_serror(), (long) len);
		return -1;
	}

	acl_vstream_close(out);
	acl_xml2_free(xml);

	return 0;
}