From 851b6f99c1248c8ec8e33322a3179c1d82fdd515 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:31:23 +0200 Subject: 6.2 --- zen/xml_io.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 zen/xml_io.cpp (limited to 'zen/xml_io.cpp') diff --git a/zen/xml_io.cpp b/zen/xml_io.cpp new file mode 100644 index 00000000..4b9abc29 --- /dev/null +++ b/zen/xml_io.cpp @@ -0,0 +1,88 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * +// ************************************************************************** + +#include "xml_io.h" +#include +#include +#include + +using namespace zen; + + +XmlDoc zen::loadXmlDocument(const Zstring& filename) //throw FileError +{ + //can't simply use zen::loadBinStream() due to the short-circuit xml-validation below! + + std::string stream; + + FileInput inputFile(filename); //throw FileError + { + //quick test whether input is an XML: avoid loading large binary files up front! + const std::string xmlBegin = "(e.row + 1)), + L"%z", numberTo(e.col + 1))); + } +} + + +void zen::saveXmlDocument(const XmlDoc& doc, const Zstring& filename) //throw FileError +{ + std::string stream = serialize(doc); //noexcept + + try + { + if (getFilesize(filename) == stream.size()) //throw FileError + if (loadBinStream(filename) == stream) //throw FileError + return; + } + catch (FileError&) {} + + FileOutput outputFile(filename, FileOutput::ACC_OVERWRITE); //throw FileError + outputFile.write(stream.c_str(), stream.length()); // +} + + +void zen::checkForMappingErrors(const XmlIn& xmlInput, const Zstring& filename) //throw FileError +{ + if (xmlInput.errorsOccured()) + { + std::wstring msg = _("Cannot read the following XML elements:") + L"\n"; + for (const std::wstring& elem : xmlInput.getErrorsAs()) + msg += L"\n" + elem; + + throw FileError(replaceCpy(_("Configuration file %x loaded partially only."), L"%x", fmtFileName(filename)) + L"\n\n" + msg); + } +} -- cgit