Skip to content

Commit ae3d107

Browse files
committed
Added boost property tree powered conversion to xml.
Still very basic. Does not really support xml attributes, but can be faked via member.
1 parent 82f0850 commit ae3d107

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

parse/jsd_generic_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace JSON
1818

1919
PropertyTree(boost::property_tree::ptree tree = {});
2020
};
21+
2122
PropertyTree parse_json(std::istream& stream);
2223
PropertyTree parse_json(std::string const& str);
2324
boost::optional<PropertyTree> parse_auto(std::istream& stream);

utility/xml_converter.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "xml_converter.h"
2+
#include "../parse/jsd_generic_parser.h"
3+
4+
#include <boost/property_tree/xml_parser.hpp>
5+
6+
#include <iostream>
7+
8+
namespace JSON
9+
{
10+
std::ostream& convertJsonToXml(std::ostream& ostream, std::istream& istream)
11+
{
12+
auto tree = parse_json(istream);
13+
14+
boost::property_tree::write_xml(ostream, tree.tree);
15+
16+
return ostream;
17+
}
18+
}

utility/xml_converter.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef XML_CONVERTER_H_INCLUDED
2+
#define XML_CONVERTER_H_INCLUDED
3+
4+
#include <iosfwd>
5+
6+
namespace JSON
7+
{
8+
/**
9+
* Converts the json istream contents to xml and writes it to the ostream.
10+
* It is not defined, what happens when streams overlap.
11+
*
12+
* @param ostream A stream to write to
13+
* @param istream A stream to read from
14+
*
15+
* @return The ostream passed as parameter;
16+
*/
17+
std::ostream& convertJsonToXml(std::ostream& ostream, std::istream& istream);
18+
}
19+
20+
#endif // XML_CONVERTER_H_INCLUDED

0 commit comments

Comments
 (0)