XMLNodeIteratorBase Class Reference
Abstract class to iterate over an xml stream.
More...
#include <XMLNodeIterator.h>
Inheritance diagram for XMLNodeIteratorBase:
List of all members.
Detailed Description
Abstract class to iterate over an xml stream.
Derive from XMLNodeIterator<ENTRYTYPE> to get an iterator that returns ENTRYTYPE objects. A derived class must provide isInterested() and process(). It should also provide a Constructor Derived(std::stream,std::string baseUrl) which must call fetchNext().
The derived iterator class should be compatible with an stl input iterator. Use like this:
for (Iterator iter(anIstream, baseUrl), iter != Iterator.end(), // or: iter() != 0, or ! iter.atEnd() ++iter) { doSomething(*iter) }
The iterator owns the pointer (i.e., caller must not delete it) until the next ++ operator is called. At this time, it will be destroyed (and a new ENTRYTYPE is created.)
If the input is fundamentally flawed so that it makes no sense to continue parsing, XMLNodeIterator will log it and consider the input as finished. You can query the exit status with errorStatus().
Constructor & Destructor Documentation
XMLNodeIteratorBase::XMLNodeIteratorBase |
( |
std::istream & |
input, |
|
|
const std::string & |
baseUrl, |
|
|
const char * |
validationPath = 0 |
|
) |
|
|
|
Constructor. Derived classes must call fetchNext() here. - Parameters:
-
| input | is the input stream (contains the xml stuff) |
| baseUrl | is the base URL of the xml document FIXME: use XMLParserError::operator<< instead of doing it on my own. |
|
XMLNodeIteratorBase::XMLNodeIteratorBase |
( |
|
) |
|
|
|
Constructor for an empty iterator. An empty iterator is already at its end. This is what end() returns ... |
virtual XMLNodeIteratorBase::~XMLNodeIteratorBase |
( |
|
) |
[virtual] |
|
|
copy constructor is forbidden. Reason: We can't copy an xmlTextReader FIXME: This prevents implementing the end() method for derived classes.
- Parameters:
-
- Returns:
|
Member Function Documentation
virtual void XMLNodeIteratorBase::_process |
( |
const xmlTextReaderPtr |
readerPtr |
) |
[protected, pure virtual] |
|
|
process an xml node and set it as next element The derived class has to produce the ENTRYTYPE object here. Details about the xml reader is in the libxml2 documentation. You'll most probably want to use xmlTextReaderExpand(reader) to request the full subtree, and then use the links in the resulting node structure to traverse, and class LibXMLHelper to access the attributes and element contents. fetchNext() cannot throw an error since it will be called in the constructor. Instead, in case of a fundamental syntax error the error is saved and will be thrown with the next checkError(). - Parameters:
-
| readerPtr | points to the xmlTextReader that reads the xml stream. |
Implemented in XMLNodeIterator< ENTRYTYPE >. |
bool XMLNodeIteratorBase::atEnd |
( |
|
) |
const |
|
|
Have we reached the end? A parser error also means "end reached" - Returns:
- whether the end has been reached.
|
static void XMLNodeIteratorBase::errorHandler |
( |
void * |
arg, |
|
|
const char * |
msg, |
|
|
int |
severity, |
|
|
xmlTextReaderLocatorPtr |
locator |
|
) |
[static, protected] |
|
|
Internal function to set the _error variable in case of a parser error. It logs the message and saves errors in _error, so that they will be thrown by checkError(). - Parameters:
-
| arg | set to this with xmlReaderSetErrorHandler() |
| msg | the error message |
| severity | the severity |
| locator | as defined by libxml2 |
|
|
returns the error status or 0 if no error the returned pointer is not-owning, it will be deleted upon destruction of the XMLNodeIterator. - Returns:
- pointer to error status (if exists)
|
void XMLNodeIteratorBase::fetchNext |
( |
|
) |
[protected] |
|
|
Fetch the next element and save it as next element |
virtual void* XMLNodeIteratorBase::getCurrent |
( |
|
) |
const [protected, pure virtual] |
|
virtual bool XMLNodeIteratorBase::isInterested |
( |
const xmlNodePtr |
nodePtr |
) |
[protected, pure virtual] |
|
|
filter for the xml nodes The derived class decides which xml nodes it is actually interested in. For each that is selected, process() will be called an the resulting ENTRYTYPE object used as the next value for the iterator. Documentation for the node structure can be found in the libxml2 documentation. Have a look at LibXMLHelper to access node attributes and contents. - Parameters:
-
| nodePtr | points to the xml node in question. Only the node is available, not the subtree. See libxml2 documentation. |
- Returns:
- true if interested
Implemented in XMLNodeIterator< ENTRYTYPE >. |
|
Opposit of operator== - Parameters:
-
- Returns:
- true if not equal
|
|
assignment is forbidden. Reason: We can't copy an xmlTextReader |
|
Two iterators are equal if both are at the end or if they are identical. Since you cannot copy an XMLNodeIterator, everything else is not equal. - Parameters:
-
- Returns:
- true if equal
|
virtual void XMLNodeIteratorBase::setCurrent |
( |
const void * |
data |
) |
[protected, pure virtual] |
|
Member Data Documentation
|
contains the base URL of the xml documentation |
|
if an error occured, this contains the error. |
|
contains the istream to read the xml file from. Can be 0 if at end or if the current element is the only element left. |
|
contains the xmlTextReader used to parse the xml file. |
The documentation for this class was generated from the following file:
Generated on Fri Jun 16 15:51:35 2006 for liby2util by
1.4.6