From 5109bffbcd72d003d2d4c2c5e0d7c366c3b5e2b4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 6 Apr 2023 09:17:48 +0100 Subject: Fix writing of XML document after XSL transform Addresses issue where document headers such as the XML declaration were omitted --- icespider/unittests/testApp.cpp | 16 ++++++++++++ icespider/unittests/testRoutes.json | 39 +++++++++++++++++++++++------- icespider/unittests/xslt/transformxml.xslt | 11 +++++++++ icespider/xslt/xsltStreamSerializer.cpp | 5 ++-- 4 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 icespider/unittests/xslt/transformxml.xslt diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp index efd328d..9f84999 100644 --- a/icespider/unittests/testApp.cpp +++ b/icespider/unittests/testApp.cpp @@ -385,10 +385,26 @@ BOOST_AUTO_TEST_CASE(testCallIndexAcceptXml) auto h = requestXml.getResponseHeaders(); BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/xml"); + BOOST_TEST_INFO(requestXml.output.view()); + BOOST_REQUIRE_NE(requestXml.output.view().find("(requestXml.output); BOOST_REQUIRE_EQUAL(v->value, "index"); } +BOOST_AUTO_TEST_CASE(testCallIndexAcceptXsltXml) +{ + TestRequest requestXml(this, HttpMethod::GET, "/"); + requestXml.hdr["Accept"] = "application/xml+test"; + process(&requestXml); + auto h = requestXml.getResponseHeaders(); + BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); + BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/xml+test"); + BOOST_TEST_INFO(requestXml.output.view()); + BOOST_REQUIRE_NE(requestXml.output.view().find(" + + + + + + + + + + diff --git a/icespider/xslt/xsltStreamSerializer.cpp b/icespider/xslt/xsltStreamSerializer.cpp index 302ec21..6fb265c 100644 --- a/icespider/xslt/xsltStreamSerializer.cpp +++ b/icespider/xslt/xsltStreamSerializer.cpp @@ -61,7 +61,7 @@ namespace IceSpider { if (!result) { throw xmlpp::exception("Failed to apply XSL transform"); } - const auto buf = std::unique_ptr { + auto buf = std::unique_ptr { xmlOutputBufferCreateIO(xmlstrmwritecallback, xmlstrmclosecallback, &strm, nullptr), &xmlOutputBufferClose}; if (xmlStrcmp(stylesheet->method, reinterpret_cast("html")) == 0) { @@ -69,8 +69,7 @@ namespace IceSpider { buf.get(), result.get(), reinterpret_cast(stylesheet->encoding), 0); } else { - xmlNodeDumpOutput(buf.get(), result.get(), result->children, 0, 0, - reinterpret_cast(stylesheet->encoding)); + xmlSaveFormatFileTo(buf.release(), result.get(), reinterpret_cast(stylesheet->encoding), 0); } } } -- cgit v1.2.3