OpenMS
Loading...
Searching...
No Matches
XMLFile.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Marc Sturm $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11// OpenMS includes
13
14#include <iosfwd>
15#include <string>
16
17namespace OpenMS
18{
19 namespace Internal
20 {
21 class XMLHandler;
22
39 class OPENMS_DLLAPI XMLFile
40 {
41
42public:
43
46
53 XMLFile(const std::string& schema_location, const std::string& version);
54
56 virtual ~XMLFile();
57
72 bool isValid(const std::string& filename, std::ostream& os);
73
75 const std::string& getVersion() const;
76
77protected:
96 void parse_(const std::string& filename, XMLHandler* handler);
97
113 void parseBuffer_(const std::string & buffer, XMLHandler * handler);
114
127 void save_(const std::string& filename, XMLHandler* handler) const;
128
129 std::string schema_location_;
130 std::string schema_version_;
131 std::string enforced_encoding_;
132
141 void enforceEncoding_(const std::string& encoding);
142 };
143
150 std::string OPENMS_DLLAPI encodeTab(const std::string& to_encode);
151 } // namespace Internal
152} // namespace OpenMS
153
Base class for loading and storing XML files via Xerces, with optional schema validation and transpar...
Definition XMLFile.h:40
std::string enforced_encoding_
Optional XML encoding override applied to the InputSource in parse_ and parseBuffer_; empty disables ...
Definition XMLFile.h:131
XMLFile(const std::string &schema_location, const std::string &version)
Construct with a schema location for later isValid calls.
XMLFile()
Construct an XMLFile without schema info; schema_location_ remains unset, so isValid cannot be used u...
void enforceEncoding_(const std::string &encoding)
Set or clear the XML-encoding override applied to subsequent parse_ / parseBuffer_ calls.
const std::string & getVersion() const
Return the schema version string passed to the parameterised constructor; empty for default-construct...
std::string schema_location_
Path of the XML schema for validation; empty when the default constructor was used (isValid then thro...
Definition XMLFile.h:129
bool isValid(const std::string &filename, std::ostream &os)
Check if filename validates against the bound XML schema.
void parse_(const std::string &filename, XMLHandler *handler)
Parse the XML file at filename through handler.
std::string schema_version_
Schema version string returned by getVersion.
Definition XMLFile.h:130
void save_(const std::string &filename, XMLHandler *handler) const
Stores the contents of the XML handler given by handler in the file given by filename.
virtual ~XMLFile()
Virtual destructor — defaulted; allows safe deletion through a base-class pointer.
void parseBuffer_(const std::string &buffer, XMLHandler *handler)
Parse an in-memory XML buffer through handler.
Base class for XML handlers.
Definition XMLHandler.h:315
std::string encodeTab(const std::string &to_encode)
Encodes tabs '\t' in the string as &#x9; and returns the encoded string.
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19