aboutsummaryrefslogtreecommitdiff
path: root/libutil++/xml_output.cpp
blob: 080c2a8d5c2afb9e868ce793600f7fd2d1231200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
 * @file xml_output.cpp
 * utility routines for writing XML
 *
 * @remark Copyright 2006 OProfile authors
 * @remark Read the file COPYING
 *
 * @author Dave Nomura
 */

#include <sstream>
#include <iostream>

#include "op_xml_out.h"
#include "xml_output.h"

using namespace std;

#define MAX_XML_BUF 16384
static char buf[MAX_XML_BUF];

string tag_name(tag_t tag)
{
	ostringstream out;
	out << xml_tag_name(tag);
	return out.str();
}


string open_element(tag_t tag, bool with_attrs)
{
	ostringstream out;

	buf[0] = '\0';
	open_xml_element(tag, with_attrs, buf, MAX_XML_BUF);
	out << buf;
	return out.str();
}


string close_element(tag_t tag, bool has_nested)
{
	ostringstream out;

	buf[0] = '\0';
	close_xml_element(tag, has_nested, buf, MAX_XML_BUF);
	out << buf;
	return out.str();
}


string init_attr(tag_t attr, size_t value)
{
	ostringstream out;

	buf[0] = '\0';
	init_xml_int_attr(attr, value, buf, MAX_XML_BUF);
	out << buf;
	return out.str();
}


string init_attr(tag_t attr, double value)
{
	ostringstream out;

	buf[0] = '\0';
	init_xml_dbl_attr(attr, value, buf, MAX_XML_BUF);
	out << buf;
	return out.str();
}


string init_attr(tag_t attr, string const & str)
{
	ostringstream out;

	buf[0] = '\0';
	init_xml_str_attr(attr, str.c_str(), buf, MAX_XML_BUF);
	out << buf;
	return out.str();
}