![]() |
Plus | - Minimal XML for C++ | (Version 0.9.2) | Giancarlo Niccolai |
#include <mxml_document.h>
Inheritance diagram for MXML::Document:
Public Member Functions | |
Document (const int style=0) | |
Creates the document object. | |
Document (Document &doc) | |
Creates a deep copy of the document. | |
Document (std::istream &in, const int style=0) throw ( MalformedError ) | |
Creates the document object and reads it. | |
~Document () | |
Destroys the document. | |
Node * | root () const |
Returns the root node. | |
int | style () const |
void | style (const int style) |
Node * | main () const |
Returns the main node, if it exists. | |
virtual void | write (std::ostream &stream, const int style) const |
Writes the document. | |
virtual void | read (std::istream &stream) throw (MalformedError) |
Reads and parse the document. | |
Private Attributes | |
Node * | m_root |
int | m_style |
Friends | |
std::ostream & | operator>> (std::ostream &stream, Document &doc) |
To work with MXML, you need to instantiate at least one object from this class; this represents the logic of a document. It is derived for an element, as an XML document must still be valid as an XML element of another document, but it implements some data specific for handling documents.
The class has the ability to parse a document into a node tree, deserializing it from a std::stream, and to output the document via the >> operator; virtual write() and read() functions overloading the element ones are also provided.
The document has an (optional) style that is used on load and eventually on write.
|
Creates the document object. This constructor does not load any document, and sets the style parameter to nothing (all defaults). Style may be changed later on with the style(int) method, but you need to do it before the document si read() if you want to set some style affects document parsing.
|
|
Creates a deep copy of the document. Each node of the original document is replicated into another separated tree. |
|
Creates the document object and reads it. The parsing may be unsuccesful, or the reading may be faulty for a defective device; if this happens, a MalformedError is thrown.
|
|
Destroys the document. If you provided a stream at document creation, the stream is NOT colsed. It's up to the caller to destroy the stream and dispose of it cleanly. |
|
Returns the main node, if it exists. Finds the main node, that is, the first (and one) tag type node at toplevel. If this node does not exists, it returns NULL.
|
|
Reads and parse the document.
#include <mxml.h> #include <iostream> #include <fstream> ... MXML::Document *readXml() { ... ifstream test_file("test.xml"); if (! test_file.is_open()) { cout << "Error opening file" << endl; exit (1); } MXML::Document *xml_doc = new MXML::Document(); try { xml_doc->read( test_file ); } catch( MXML::Error &er ) { std::cout << std::endl << er << std::endl; delete xml_doc; xml_doc = 0; } return xml_doc; }
|
|
Returns the root node. The root node is always a root node type; this means that it has no name, attributes nor data: it's just a container for the other top level nodes. |
|
|
|
|
|
Writes the document.
Implements MXML::Element. |
|
|
|
|
|
|