Home | History | Annotate | Download | only in libutil++
      1 /**
      2  * @file xml_output.cpp
      3  * utility routines for writing XML
      4  *
      5  * @remark Copyright 2006 OProfile authors
      6  * @remark Read the file COPYING
      7  *
      8  * @author Dave Nomura
      9  */
     10 
     11 #include <sstream>
     12 #include <iostream>
     13 
     14 #include "op_xml_out.h"
     15 #include "xml_output.h"
     16 
     17 using namespace std;
     18 
     19 #define MAX_XML_BUF 16384
     20 static char buf[MAX_XML_BUF];
     21 
     22 string tag_name(tag_t tag)
     23 {
     24 	ostringstream out;
     25 	out << xml_tag_name(tag);
     26 	return out.str();
     27 }
     28 
     29 
     30 string open_element(tag_t tag, bool with_attrs)
     31 {
     32 	ostringstream out;
     33 
     34 	buf[0] = '\0';
     35 	open_xml_element(tag, with_attrs, buf, MAX_XML_BUF);
     36 	out << buf;
     37 	return out.str();
     38 }
     39 
     40 
     41 string close_element(tag_t tag, bool has_nested)
     42 {
     43 	ostringstream out;
     44 
     45 	buf[0] = '\0';
     46 	close_xml_element(tag, has_nested, buf, MAX_XML_BUF);
     47 	out << buf;
     48 	return out.str();
     49 }
     50 
     51 
     52 string init_attr(tag_t attr, size_t value)
     53 {
     54 	ostringstream out;
     55 
     56 	buf[0] = '\0';
     57 	init_xml_int_attr(attr, value, buf, MAX_XML_BUF);
     58 	out << buf;
     59 	return out.str();
     60 }
     61 
     62 
     63 string init_attr(tag_t attr, double value)
     64 {
     65 	ostringstream out;
     66 
     67 	buf[0] = '\0';
     68 	init_xml_dbl_attr(attr, value, buf, MAX_XML_BUF);
     69 	out << buf;
     70 	return out.str();
     71 }
     72 
     73 
     74 string init_attr(tag_t attr, string const & str)
     75 {
     76 	ostringstream out;
     77 
     78 	buf[0] = '\0';
     79 	init_xml_str_attr(attr, str.c_str(), buf, MAX_XML_BUF);
     80 	out << buf;
     81 	return out.str();
     82 }
     83