BOOST_AUTO_TEST_CASE(ReadAndWriteWithSpecialCharacters) { using boost::property_tree::ptree; // the xml that will be turned into a ptree. Note the linefeed between Level_1 and Level_2 tags std::string XmlString = "\n0"; std::stringstream StringStream1(XmlString); std::stringstream StringStream2; // read the xml string ptree Level1Tree; read_xml(StringStream1,Level1Tree); // write the sub-tree at level 1 to string stream 2 as an xml ptree Level2Tree = Level1Tree.get_child("Level_1"); write_xml(StringStream2,Level2Tree); // show that the xml string has an xml declaration followed by \n (boost version 1.56) // or an xml declaration followed by \n\n (boost version 1.55 and earlier) std::string Level2XmlString = StringStream2.str(); if (BOOST_VERSION >= 105600) { BOOST_CHECK(Level2XmlString == "\n 0"); } else { BOOST_CHECK(Level2XmlString == "\n\n0"); } // reading the xml from string stream 2 throws an exception in boost 1.56 but not in boost 1.55 ptree OutputTree; BOOST_CHECK_NO_THROW(read_xml(StringStream2,OutputTree)); }