From b874f81abc09af1f07046c1f4b42793fed8aad8d Mon Sep 17 00:00:00 2001 From: valnoel Date: Mon, 18 Nov 2013 13:53:58 +0100 Subject: [PATCH] write xml report in file issue #30 --- libraries/Comparator/test/comparatorTest.cpp | 3 +-- .../src/ReportGenerator/Report.cpp | 17 ++++++++++++----- .../src/ReportGenerator/Report.hpp | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libraries/Comparator/test/comparatorTest.cpp b/libraries/Comparator/test/comparatorTest.cpp index ce64a3d..023c460 100644 --- a/libraries/Comparator/test/comparatorTest.cpp +++ b/libraries/Comparator/test/comparatorTest.cpp @@ -129,7 +129,6 @@ BOOST_AUTO_TEST_CASE( comparator_test_comparator_1 ) BOOST_CHECK_EQUAL( file.isEndOfFile(), true ); report.print(); - report.writeXml(); } BOOST_AUTO_TEST_CASE( comparator_test_comparator_2 ) @@ -253,7 +252,7 @@ BOOST_AUTO_TEST_CASE( comparator_test_comparator_2 ) BOOST_CHECK_EQUAL( file.isEndOfFile(), true ); report.print(); - report.writeXml(); + report.writeXml( "test.xml" ); } BOOST_AUTO_TEST_CASE( comparator_test_comparator_3 ) diff --git a/libraries/ReportGenerator/src/ReportGenerator/Report.cpp b/libraries/ReportGenerator/src/ReportGenerator/Report.cpp index 0a5e746..e917ca7 100644 --- a/libraries/ReportGenerator/src/ReportGenerator/Report.cpp +++ b/libraries/ReportGenerator/src/ReportGenerator/Report.cpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -107,9 +108,14 @@ void addXmlNodeAttribute( rapidxml::xml_document<>& doc, rapidxml::xml_node<>* n } -void Report::writeXml() +void Report::writeXml( const std::string& filename ) { rapidxml::xml_document<> doc; + + rapidxml::xml_node<>* declaration = doc.allocate_node( rapidxml::node_declaration ); + declaration->append_attribute( doc.allocate_attribute( "version", "1.0" ) ); + declaration->append_attribute( doc.allocate_attribute( "encoding", "utf-8" ) ); + doc.append_node( declaration ); rapidxml::xml_node<>* prevNode = nullptr; rapidxml::xml_node<>* node = nullptr; @@ -180,12 +186,13 @@ void Report::writeXml() } prevNode = node; - } - rapidxml::print( std::cout, doc, 0 ); -} - + // rapidxml::print( std::cout, doc, 0 ); + std::ofstream file( filename ); + file << doc; + file.close(); +} } diff --git a/libraries/ReportGenerator/src/ReportGenerator/Report.hpp b/libraries/ReportGenerator/src/ReportGenerator/Report.hpp index cbbf66a..1e661cc 100644 --- a/libraries/ReportGenerator/src/ReportGenerator/Report.hpp +++ b/libraries/ReportGenerator/src/ReportGenerator/Report.hpp @@ -23,7 +23,7 @@ class Report void init( const std::vector< std::shared_ptr< basic_element::Element > >& elementList ); void print(); void print( const std::shared_ptr< basic_element::Element > element, const std::string& dispColor ); - void writeXml(); + void writeXml( const std::string& filename ); private: std::vector< std::shared_ptr< basic_element::Element > > _elementList;