#include <XmlWriter.hpp>
Public Member Functions | |
XmlWriter (const XmlWriter &)=delete | |
XmlWriter (std::ostream &outputStream, string streamName) | |
XmlWriter (string filePath) | |
XmlWriter & | operator= (const XmlWriter &)=delete |
void | writeAttribute (string name, string value) |
void | writeComment (string text) |
void | writeEndDocument () |
void | writeEndElement () |
void | writeStartDocument () |
void | writeStartElement (string name) |
Private Member Functions | |
void | writeIndentation () |
Private Attributes | |
vector< string > | _elementNames |
std::ostream & | _out |
std::ofstream | _outfile |
bool | _starting |
string | _streamName |
The XmlWriter class facilates writing the subset of XML that is sufficient to represent SMILE schemas and datasets. The output stream is garantueed to be a well-formed XML 1.0 document that also conforms to the limitations described for the XmlReader class, so that it can be parsed by that class.
When an error occurs while writing the XML data stream, the constructor and methods of this class throw a FatalError with an appropriate error message.
XmlWriter::XmlWriter | ( | std::ostream & | outputStream, |
string | streamName | ||
) |
This constructor accepts and retains a reference to the output stream to be written, and initializes the XML writer. The second argument provides a human readable string to identify the stream in error messages.
XmlWriter::XmlWriter | ( | string | filePath | ) |
This constructor creates and opens the file with the specified path as the output stream to be written, and initializes the XML writer. The file path is used to identify the stream in error messages.
|
delete |
The copy constructor is deleted because instances of this class should never be copied or moved.
The assignment operator is deleted because instances of this class should never be copied or moved.
void XmlWriter::writeAttribute | ( | string | name, |
string | value | ||
) |
Writes an attribute with the specified name and value. This function can only be called after writeStartElement() before any further content is written.
void XmlWriter::writeComment | ( | string | text | ) |
Writes the specified text as XML comment. The text must not contain the forbidden sequence "--" or end with "-". Note that XML does not provide any way to escape "-" in a comment.
void XmlWriter::writeEndDocument | ( | ) |
Verifies that the number of writeStartElement() and writeEndElement() invocations match, and that the output stream is in a non-error state. If not, a FatalError is thrown. This function must be called once after any of the other functions are called.
void XmlWriter::writeEndElement | ( | ) |
Closes the previous matching start element. For a particular XML document, the number of invocations of this function must exactly match the number of invocations of the writeStartElement() function. This is verified in the writeEndDocument() function.
|
private |
Writes
void XmlWriter::writeStartDocument | ( | ) |
Writes a document start with the appropriate XML version and encoding information. This function must be called once before any of the other functions are called.
void XmlWriter::writeStartElement | ( | string | name | ) |
Writes a start element with the specified name. Subsequent calls to writeAttribute() will add attributes to this element.