コード例 #1
0
int create_test_file(){
	Test t;
	Xml xml;
	int i, j;
	String str;

	t.start("create test file");

	Xml::remove("/home/xml_test.xml");

	if( xml.init("/home/xml_test.xml", Xml::WRITEONLY) < 0 ){
		t.failed("failed to create test file");
		perror("failed to open");
		return -1;
	}
	t.passed();

	t.start("write data");
	if( xml.write_start_tag("xml") < 0 ){ t.failed("failed xml start"); return -1; } t.update();
	for(i=0; i < 10; i++){
		if( xml.write_start_tag("data") < 0 ){ t.failed("failed data start"); return -1; } t.update();
		for(j=0; j < 10; j++){
			str.clear();
			str.setformat(String::DECIMAL, 8);
			str << i*10 + j;
			if( xml.write_element("array", str.c_str()) < 0 ){ t.failed("failed array"); return -1; } t.update();
		}
		if( xml.write_end_tag("data") < 0 ){ t.failed("failed data end"); return -1; } t.update();
	}
	if( xml.write_end_tag("xml") < 0 ){ t.failed("failed xml end"); return -1; } t.update();
	t.passed();

	t.start("xml close");
	if( xml.close() < 0 ){ t.failed("failed"); return -1; }
	t.passed();

	return 0;
}