OpenMS  2.7.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
XMLFile Class Reference

Base class for loading/storing XML files that have a handler derived from XMLHandler. More...

#include <OpenMS/FORMAT/XMLFile.h>

Inheritance diagram for XMLFile:
[legend]
Collaboration diagram for XMLFile:
[legend]

Public Member Functions

 XMLFile ()
 Default constructor. More...
 
 XMLFile (const String &schema_location, const String &version)
 Constructor that sets the schema location. More...
 
virtual ~XMLFile ()
 Destructor. More...
 
bool isValid (const String &filename, std::ostream &os)
 Checks if a file validates against the XML schema. More...
 
const StringgetVersion () const
 return the version of the schema More...
 

Protected Member Functions

void parse_ (const String &filename, XMLHandler *handler)
 Parses the XML file given by filename using the handler given by handler. More...
 
void parseBuffer_ (const std::string &buffer, XMLHandler *handler)
 Parses the in-memory buffer given by buffer using the handler given by handler. More...
 
void save_ (const String &filename, XMLHandler *handler) const
 Stores the contents of the XML handler given by handler in the file given by filename. More...
 
void enforceEncoding_ (const String &encoding)
 

Protected Attributes

String schema_location_
 XML schema file location. More...
 
String schema_version_
 Version string. More...
 
String enforced_encoding_
 Encoding string that replaces the encoding (system dependent or specified in the XML). Disabled if empty. Used as a workaround for XTandem output xml. More...
 

Detailed Description

Base class for loading/storing XML files that have a handler derived from XMLHandler.

Constructor & Destructor Documentation

◆ XMLFile() [1/2]

XMLFile ( )

Default constructor.

◆ XMLFile() [2/2]

XMLFile ( const String schema_location,
const String version 
)

Constructor that sets the schema location.

◆ ~XMLFile()

virtual ~XMLFile ( )
virtual

Destructor.

Member Function Documentation

◆ enforceEncoding_()

void enforceEncoding_ ( const String encoding)
protected

◆ getVersion()

const String& getVersion ( ) const

return the version of the schema

◆ isValid()

bool isValid ( const String filename,
std::ostream &  os 
)

Checks if a file validates against the XML schema.

Error messages are printed to the error stream, unless redirected with the attribute os .

Parameters
filenameThe name of the file to validate.
osThe ostream where error messages should be send.
Exceptions
Exception::FileNotFoundis thrown if the file cannot be found
Exception::NotImplementedis thrown if there is no schema available for the file type

◆ parse_()

void parse_ ( const String filename,
XMLHandler handler 
)
protected

Parses the XML file given by filename using the handler given by handler.

Exceptions
Exception::FileNotFoundis thrown if the file is not found
Exception::ParseErroris thrown if an error occurred during the parsing

◆ parseBuffer_()

void parseBuffer_ ( const std::string &  buffer,
XMLHandler handler 
)
protected

Parses the in-memory buffer given by buffer using the handler given by handler.

Note
Currently the buffer needs to be plain text, gzip buffer is not supported.
Exceptions
Exception::ParseErroris thrown if an error occurred during the parsing

◆ save_()

void save_ ( const String filename,
XMLHandler handler 
) const
protected

Stores the contents of the XML handler given by handler in the file given by filename.

Exceptions
Exception::UnableToCreateFileis thrown if the file cannot be created

Member Data Documentation

◆ enforced_encoding_

String enforced_encoding_
protected

Encoding string that replaces the encoding (system dependent or specified in the XML). Disabled if empty. Used as a workaround for XTandem output xml.

◆ schema_location_

String schema_location_
protected

XML schema file location.

◆ schema_version_

String schema_version_
protected

Version string.