Plus  - Minimal XML for C++ (Version 0.9.2) Giancarlo Niccolai
Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MXML::Document Class Reference

Class containing a logical XML file representation. More...

#include <mxml_document.h>

Inheritance diagram for MXML::Document:

Inheritance graph
[legend]
Collaboration diagram for MXML::Document:

Collaboration graph
[legend]
List of all members.

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.

Noderoot () const
 Returns the root node.

int style () const
void style (const int style)
Nodemain () 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

Nodem_root
int m_style

Friends

std::ostream & operator>> (std::ostream &stream, Document &doc)

Detailed Description

Class containing a logical XML file representation.

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.

See also:
stylemacros


Constructor & Destructor Documentation

MXML::Document::Document const int  style = 0  ) 
 

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.

Parameters:
style the mode in which the document is read/written
See also:
stylemacros

read

MXML::Document::Document Document doc  ) 
 

Creates a deep copy of the document.

Each node of the original document is replicated into another separated tree.

MXML::Document::Document std::istream &  in,
const int  style = 0
throw ( MalformedError )
 

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.

Parameters:
in the stream in which the data is read.
style the mode in which the document is read/written
See also:
stylemacros

MXML::Document::~Document  ) 
 

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.


Member Function Documentation

Node * MXML::Document::main  )  const
 

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.

Returns:
the main node or null

void MXML::Document::read std::istream &  stream  )  throw (MalformedError) [virtual]
 

Reads and parse the document.

Todo:
throw an exception on error, or return a value. Reads the document from the stream; in case of error the status of the document will be faulty.
Example:
      #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;
      }

Parameters:
stream the input stream used for reading the data.
See also:
Node::read()

Node* MXML::Document::root  )  const [inline]
 

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.

void MXML::Document::style const int  style  )  [inline]
 

int MXML::Document::style  )  const [inline]
 

void MXML::Document::write std::ostream &  stream,
const int  style
const [virtual]
 

Writes the document.

Todo:
throw an exception on error, or return a value. Writes the document to the stream; in case of error the status of the document will be faulty.
See also:
Node::write()

Implements MXML::Element.


Friends And Related Function Documentation

std::ostream& operator>> std::ostream &  stream,
Document doc
[friend]
 


Member Data Documentation

Node* MXML::Document::m_root [private]
 

int MXML::Document::m_style [private]
 


The documentation for this class was generated from the following files:
Generated on Sun Apr 11 02:08:21 2004 for Mxml Plus by doxygen 1.3.5