btool
A parser/converter/transpiler for .bib files
XmlGenerator.cpp
Go to the documentation of this file.
1
#include <
XmlGenerator.hpp
>
2
#include <sstream>
3
8
XmlGenerator::XmlGenerator
(
const
std::vector<BibElement> &elements) :
AbstractGenerator
{
elements
} {}
9
15
auto
XmlGenerator::write
() -> std::string {
16
std::stringstream ss;
17
ss << R
"(<?xml version="1.0" encoding="UTF-8" standalone="yes"?>)" <<
'\n'
;
18
ss <<
"<bibElements>\n"
;
19
for
(
const
auto
& element : elements) {
20
ss <<
"\t<element>\n"
;
21
ss <<
"\t\t<id>\n\t\t\t"
<< element.id <<
"\n\t\t</id>\n"
;
22
ss <<
"\t\t<style>\n\t\t\t"
<< element.style <<
"\n\t\t</style>\n"
;
23
ss <<
"\t\t<attributes>\n"
;
24
for
(
const
auto
& attribute : element.attributes) {
25
ss <<
"\t\t\t<"
<< attribute.name <<
">"
<< attribute.value <<
"</"
<< attribute.name <<
">\n"
;
26
}
27
ss <<
"\t\t</attributes>\n"
;
28
ss <<
"\t</element>\n"
;
29
}
30
ss <<
"</bibElements>\n"
;
31
return
ss.str();
32
}
33
38
auto
XmlGenerator::fail
(
const
std::string &message,
const
std::string &type) ->
void
{
39
AbstractGenerator::fail
(message,
"XML"
);
40
}
AbstractGenerator
Definition:
AbstractGenerator.hpp:14
XmlGenerator.hpp
AbstractGenerator::fail
virtual auto fail(const std::string &message, const std::string &type="unknown") -> void
Definition:
AbstractGenerator.cpp:12
XmlGenerator::fail
auto fail(const std::string &message, const std::string &type) -> void override
Definition:
XmlGenerator.cpp:38
XmlGenerator::write
auto write() -> std::string override
Definition:
XmlGenerator.cpp:15
XmlGenerator::XmlGenerator
XmlGenerator(const std::vector< BibElement > &elements)
Definition:
XmlGenerator.cpp:8
AbstractGenerator::elements
std::vector< BibElement > elements
Elements to write.
Definition:
AbstractGenerator.hpp:16
src
XmlGenerator.cpp
Generated by
1.8.19