Skip to content

Commit

Permalink
write xml report in file
Browse files Browse the repository at this point in the history
issue #30
  • Loading branch information
valnoel committed Nov 18, 2013
1 parent 237a5cf commit b874f81
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 1 addition & 2 deletions libraries/Comparator/test/comparatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
17 changes: 12 additions & 5 deletions libraries/ReportGenerator/src/ReportGenerator/Report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <iostream>
#include <sstream>
#include <fstream>

#include <BasicElement/Element.hpp>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

}
2 changes: 1 addition & 1 deletion libraries/ReportGenerator/src/ReportGenerator/Report.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b874f81

Please sign in to comment.