XML file reader. More...
#include <xmlstorage.h>
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 XMLFormat & | get_format () const |
const char * | get_endl () const |
const XMLErrorList & | get_errors () const |
const XMLErrorList & | get_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 |
XML file reader.
Definition at line 2752 of file xmlstorage.h.
anonymous enum [protected, inherited] |
XMLStorage::XMLReader::XMLReader | ( | XMLNode * | node, |
std::istream & | in | ||
) | [inline] |
Definition at line 2754 of file xmlstorage.h.
: XMLReaderBase(node), _in(in), _last_crlf(0) { }
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().
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); }
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; }
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(); }
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(); }
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";}
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;}
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;}
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();}
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 }
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(); }
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);}
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(); }
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; }
friend struct ParseContext [friend, inherited] |
Definition at line 2701 of file xmlstorage.h.
std::string XMLStorage::XMLReaderBase::_content [protected, inherited] |
Definition at line 2669 of file xmlstorage.h.
Referenced by XMLStorage::XMLReaderBase::DefaultHandler(), and XMLStorage::XMLReaderBase::get_encoded_content().
bool XMLStorage::XMLReaderBase::_endl_defined [protected, inherited] |
Definition at line 2676 of file xmlstorage.h.
Referenced by XMLStorage::XMLReaderBase::get_endl(), and XMLStorage::ParseContext::process_next().
XMLErrorList XMLStorage::XMLReaderBase::_errors [protected, inherited] |
Definition at line 2672 of file xmlstorage.h.
Referenced by XMLStorage::XMLReaderBase::clear_errors(), XMLStorage::XMLReaderBase::get_errors(), and XMLStorage::XMLReaderBase::read().
XMLFormat XMLStorage::XMLReaderBase::_format [protected, inherited] |
Definition at line 2675 of file xmlstorage.h.
Referenced by XMLStorage::XMLReaderBase::get_endl(), XMLStorage::XMLReaderBase::get_format(), XMLStorage::ParseContext::process_next(), and XMLStorage::ParseContext::read_bom().
std::istream& XMLStorage::XMLReader::_in [protected] |
Definition at line 2787 of file xmlstorage.h.
Referenced by get().
int XMLStorage::XMLReader::_last_crlf [protected] |
Definition at line 2788 of file xmlstorage.h.
Referenced by get().
enum { ... } XMLStorage::XMLReaderBase::_last_tag [protected, inherited] |
Referenced by XMLStorage::XMLReaderBase::XMLReaderBase().
XMLLocation XMLStorage::XMLReaderBase::_location [protected, inherited] |
Definition at line 2679 of file xmlstorage.h.
Referenced by get(), XMLStorage::XMLReaderBase::get_location(), XMLStorage::XMLReaderBase::get_position(), and XMLStorage::XMLReaderBase::setSystemId().
XMLPos XMLStorage::XMLReaderBase::_pos [protected, inherited] |
Definition at line 2667 of file xmlstorage.h.
XMLErrorList XMLStorage::XMLReaderBase::_warnings [protected, inherited] |
Definition at line 2673 of file xmlstorage.h.
Referenced by XMLStorage::XMLReaderBase::clear_errors(), and XMLStorage::XMLReaderBase::get_warnings().