Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends

XMLStorage::XMLReader Struct Reference

XML file reader. More...

#include <xmlstorage.h>

Inheritance diagram for XMLStorage::XMLReader:
Inheritance graph
[legend]
Collaboration diagram for XMLStorage::XMLReader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 XMLReader (XMLNode *node, std::istream &in)
int get ()
 read one character from XML stream
bool parse (bool force_utf8=false)
void read (bool force_utf8=false)
 read XML stream into XML tree below _pos
std::string get_position () const
const XMLFormatget_format () const
const char * get_endl () const
const XMLErrorListget_errors () const
const XMLErrorListget_warnings () const
void clear_errors ()
XMLLocation get_location () const
void setSystemId (const char *systemId)
std::string get_encoded_content () const

Protected Types

enum  { TAG_NONE, TAG_START, TAG_END }

Protected Member Functions

int eat_endl ()
void finish_read ()
virtual void XmlDeclHandler (const char *version, const char *encoding, int standalone)
 store XML version and encoding into XML reader
virtual void StartElementHandler (const XS_String &name, const XMLNode::AttributeMap &attributes)
 notifications about XML start tag
virtual void EndElementHandler ()
 notifications about XML end tag
virtual void DefaultHandler (const std::string &s)
 store content, white space and comments

Protected Attributes

std::istream & _in
int _last_crlf
XMLPos _pos
std::string _content
enum
XMLStorage::XMLReaderBase:: { ... }  
_last_tag
XMLErrorList _errors
XMLErrorList _warnings
XMLFormat _format
bool _endl_defined
XMLLocation _location

Friends

struct ParseContext

Detailed Description

XML file reader.

Definition at line 2752 of file xmlstorage.h.


Member Enumeration Documentation

anonymous enum [protected, inherited]
Enumerator:
TAG_NONE 
TAG_START 
TAG_END 

Definition at line 2670 of file xmlstorage.h.


Constructor & Destructor Documentation

XMLStorage::XMLReader::XMLReader ( XMLNode node,
std::istream &  in 
) [inline]

Definition at line 2754 of file xmlstorage.h.

     :  XMLReaderBase(node),
        _in(in),
        _last_crlf(0)
    {
    }

Member Function Documentation

void XMLStorage::XMLReaderBase::clear_errors (  ) [inline, inherited]

Definition at line 2648 of file xmlstorage.h.

References XMLStorage::XMLReaderBase::_errors, and XMLStorage::XMLReaderBase::_warnings.

Referenced by XMLStorage::XMLDoc::read().

{_errors.clear(); _warnings.clear();}

Here is the caller graph for this function:

void XMLStorage::XMLReaderBase::DefaultHandler ( const std::string &  s ) [protected, virtual, inherited]

store content, white space and comments

Reimplemented in XMLStorage::XMLStateReader.

Definition at line 460 of file xs-native.cpp.

References XMLStorage::XMLReaderBase::_content.

Referenced by XMLStorage::ParseContext::process_next().

{
    _content.append(s);
}

Here is the caller graph for this function:

int XMLStorage::XMLReaderBase::eat_endl (  ) [protected, inherited]

Definition at line 445 of file xs-native.cpp.

Referenced by XMLStorage::ParseContext::process_next().

{
    int c = get();

    if (c == '\r')
        c = get();

    if (c == '\n')
        c = get();

    return c;
}

Here is the caller graph for this function:

void XMLStorage::XMLReaderBase::EndElementHandler (  ) [protected, virtual, inherited]

notifications about XML end tag

Reimplemented in XMLStorage::XMLStateReader.

Definition at line 978 of file xmlstorage.cpp.

References XMLStorage::XMLNode::_content, CDATA_END, and CDATA_START.

Referenced by XMLStorage::ParseContext::process_next().

{
    const char* s = _content.c_str();
    const char* e = s + _content.length();
    const char* p;

    if (!strncmp(s,CDATA_START,9) && !strncmp(e-3,CDATA_END,3)) {
        s += 9;
        p = (e-=3);

        _pos->_cdata_content = true;
    } else {
         // search for content end leaving only white space for _end_leading
        for(p=e; p>s; --p)
            if (!isspace((unsigned char)p[-1]))
                break;

        _pos->_cdata_content = false;
    }

    if (p != s) {
        if (_pos->_children.empty())    // no children in current node?
            _pos->_content.append(s, p-s);
        else if (_last_tag == TAG_START)
            _pos->_content.append(s, p-s);
        else
            _pos->_children.back()->_trailing.append(s, p-s);
    }

    if (p != e)
        _pos->_end_leading.assign(p, e-p);

    _pos.back();

    _last_tag = TAG_END;
    _content.erase();
}

Here is the caller graph for this function:

void XMLStorage::XMLReaderBase::finish_read (  ) [protected, inherited]

Definition at line 908 of file xmlstorage.cpp.

References XMLStorage::XMLNode::_content.

Referenced by XMLStorage::XMLReaderBase::read().

{
    if (_pos != NULL) {
        if (_pos->_children.empty())
            _pos->_trailing.append(_content);
        else
            _pos->_children.back()->_trailing.append(_content);
    }

    _content.erase();
}

Here is the caller graph for this function:

int XMLStorage::XMLReader::get (  ) [inline, virtual]

read one character from XML stream

Implements XMLStorage::XMLReaderBase.

Definition at line 2762 of file xmlstorage.h.

References XMLStorage::XMLLocation::_column, _in, _last_crlf, XMLStorage::XMLLocation::_line, and XMLStorage::XMLReaderBase::_location.

    {
        int c = _in.get();

//       // increment line counter on LF
//      if (c == '\n') {
//          _location._column = 1;
//          ++_location._line;
         // increment line counter on LF, CR, CR/LF or LF/CR line endings
        if (c=='\n' || c=='\r') {
            if (!_last_crlf || c==_last_crlf) {
                _location._column = 1;
                ++_location._line;
                _last_crlf = c;
            } else
                _last_crlf = 0;
        } else {
            ++_location._column;
            _last_crlf = 0;
        }

        return c;
    }
std::string XMLStorage::XMLReaderBase::get_encoded_content (  ) const [inline, inherited]

Definition at line 2664 of file xmlstorage.h.

References XMLStorage::XMLReaderBase::_content.

{return _content;}
const char* XMLStorage::XMLReaderBase::get_endl (  ) const [inline, inherited]

Definition at line 2643 of file xmlstorage.h.

References XMLStorage::XMLFormat::_endl, XMLStorage::XMLReaderBase::_endl_defined, and XMLStorage::XMLReaderBase::_format.

Referenced by XMLStorage::XMLDoc::read().

{return _endl_defined? _format._endl: "\n";}

Here is the caller graph for this function:

const XMLErrorList& XMLStorage::XMLReaderBase::get_errors (  ) const [inline, inherited]

Definition at line 2645 of file xmlstorage.h.

References XMLStorage::XMLReaderBase::_errors.

Referenced by XMLStorage::XMLStreamReader::get_errors(), and XMLStorage::XMLDoc::read().

{return _errors;}

Here is the caller graph for this function:

const XMLFormat& XMLStorage::XMLReaderBase::get_format (  ) const [inline, inherited]

Definition at line 2642 of file xmlstorage.h.

References XMLStorage::XMLReaderBase::_format.

Referenced by XMLStorage::XMLDoc::read().

{return _format;}

Here is the caller graph for this function:

XMLLocation XMLStorage::XMLReaderBase::get_location (  ) const [inline, inherited]

Definition at line 2651 of file xmlstorage.h.

References XMLStorage::XMLReaderBase::_location.

{return _location;}
std::string XMLStorage::XMLReaderBase::get_position (  ) const [inline, inherited]

Definition at line 2640 of file xmlstorage.h.

References XMLStorage::XMLReaderBase::_location, and XMLStorage::XMLLocation::str().

{return _location.str();}

Here is the call graph for this function:

const XMLErrorList& XMLStorage::XMLReaderBase::get_warnings (  ) const [inline, inherited]

Definition at line 2646 of file xmlstorage.h.

References XMLStorage::XMLReaderBase::_warnings.

{return _warnings;}
bool XMLStorage::XMLReaderBase::parse ( bool  force_utf8 = false ) [inherited]

Definition at line 435 of file xs-native.cpp.

References XMLStorage::ParseContext::proceed().

Referenced by XMLStorage::XMLReaderBase::read().

{
    ParseContext ctx(*this, force_utf8);

    while(ctx.proceed()) {
    }

    return true; //TODO return false on invalid XML
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLStorage::XMLReaderBase::read ( bool  force_utf8 = false ) [inherited]

read XML stream into XML tree below _pos

Definition at line 57 of file xs-native.cpp.

References XMLStorage::XMLReaderBase::_errors, XMLStorage::XMLReaderBase::finish_read(), and XMLStorage::XMLReaderBase::parse().

Referenced by XMLStorage::XMLDoc::read().

{
    if (!parse(force_utf8)) {
        XMLError error("XML parsing error");
        //error._line = ;
        //error._column = ;

        _errors.push_back(error);
    }

    finish_read();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLStorage::XMLReaderBase::setSystemId ( const char *  systemId ) [inline, inherited]

Definition at line 2652 of file xmlstorage.h.

References XMLStorage::XMLReaderBase::_location, and XMLStorage::XMLLocation::set_path().

Referenced by XMLStorage::XMLDoc::read(), and XMLStorage::XMLStreamReader::XMLStreamReader().

{_location.set_path(systemId);}

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLStorage::XMLReaderBase::StartElementHandler ( const XS_String name,
const XMLNode::AttributeMap attributes 
) [protected, virtual, inherited]

notifications about XML start tag

Reimplemented in XMLStorage::XMLStateReader.

Definition at line 935 of file xmlstorage.cpp.

References XMLStorage::XMLNode::_attributes, XMLStorage::XMLNode::_content, and XMLStorage::XMLNode::XMLNode().

Referenced by XMLStorage::ParseContext::process_next().

{
    const char* s = _content.c_str();
    const char* e = s + _content.length();
    const char* p = s;

     // search for content end leaving only white space for leading
    for(p=e; p>s; --p)
        if (!isspace((unsigned char)p[-1]))
            break;

    if (p != s) {
        if (_pos->_children.empty()) {  // no children in last node?
            if (_last_tag == TAG_START)
                _pos->_content.append(s, p-s);
            else if (_last_tag == TAG_END)
                _pos->_trailing.append(s, p-s);
            else // TAG_NONE at root node
                p = s;
        } else
            _pos->_children.back()->_trailing.append(s, p-s);
    }

    std::string leading;

    if (p != e)
        leading.assign(p, e-p);

    XMLNode* node = new XMLNode(name, leading);

    _pos.add_down(node);

#ifdef XMLNODE_LOCATION
    node->_location = get_location();
#endif

    node->_attributes = attributes;

    _last_tag = TAG_START;
    _content.erase();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLStorage::XMLReaderBase::XmlDeclHandler ( const char *  version,
const char *  encoding,
int  standalone 
) [protected, virtual, inherited]

store XML version and encoding into XML reader

Definition at line 922 of file xmlstorage.cpp.

Referenced by XMLStorage::ParseContext::process_next().

{
    if (version)
        _format._version = version;

    if (encoding)
        _format._encoding = encoding;

    _format._standalone = standalone;
}

Here is the caller graph for this function:


Friends And Related Function Documentation

friend struct ParseContext [friend, inherited]

Definition at line 2701 of file xmlstorage.h.


Member Data Documentation

std::string XMLStorage::XMLReaderBase::_content [protected, inherited]
bool XMLStorage::XMLReaderBase::_endl_defined [protected, inherited]
std::istream& XMLStorage::XMLReader::_in [protected]

Definition at line 2787 of file xmlstorage.h.

Referenced by get().

Definition at line 2788 of file xmlstorage.h.

Referenced by get().

enum { ... } XMLStorage::XMLReaderBase::_last_tag [protected, inherited]
XMLPos XMLStorage::XMLReaderBase::_pos [protected, inherited]

Definition at line 2667 of file xmlstorage.h.


The documentation for this struct was generated from the following file: