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

XMLStorage::XMLDoc Struct Reference

XML document holder. More...

#include <xmlstorage.h>

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

List of all members.

Public Types

enum  COPY_FLAGS { COPY_NOCHILDREN }
typedef std::string super

Public Member Functions

 XMLDoc ()
 XMLDoc (LPCTSTR path, bool force_utf8=false)
bool read_file (LPCTSTR path, bool force_utf8=false)
bool read_buffer (const char *buffer, size_t len, const std::string &system_id=std::string(), bool force_utf8=false)
bool read_buffer (const std::string &buffer, const std::string &system_id=std::string(), bool force_utf8=false)
bool read_stream (std::istream &in, const std::string &system_id=std::string(), bool force_utf8=false)
bool read (XMLReaderBase &reader, const std::string &display_path, bool force_utf8=false)
bool write (std::ostream &out, WRITE_MODE mode=FORMAT_SMART) const
 write XML stream
bool write_formating (std::ostream &out) const
 write XML stream with formating
bool write_file (LPCTSTR path, WRITE_MODE mode=FORMAT_SMART) const
bool write_formating (LPCTSTR path) const
void clear ()
void add_child (XMLNode *child)
 add a new child node
void remove_children (const XS_String &name)
 remove all children named 'name'
void put (const XS_String &attr_name, const XS_String &value)
 write access to an attribute
XS_Stringoperator[] (const XS_String &attr_name)
 index operator write access to an attribute
XS_String operator[] (const XS_String &attr_name) const
 index operator read access to an attribute
template<typename T >
XS_String get (const T &attr_name, LPCXSSTR def=XS_EMPTY_STR) const
 read only access to an attribute
void erase (const XS_String &attr_name)
 remove the attribute 'attr_name'
XS_String subvalue (const XS_String &child_name, const XS_String &attr_name, int n=0) const
 convenient value access in children node
XS_Stringsubvalue (const XS_String &child_name, const XS_String &attr_name, int n=0)
 convenient storage of distinct values in children node
const Childrenget_children () const
Childrenget_children ()
const AttributeMapget_attributes () const
AttributeMapget_attributes ()
XS_String get_content () const
 read element node content
std::string get_encoded_content () const
 read element node content as encoded string
XS_String get_sub_content (const XPath &xpath) const
 read content of a subnode specified by an XPath expression
void set_content (const XS_String &s, bool cdata=false)
 set element node content
void set_encoded_content (const std::string &s)
 set element node content from encoded string
bool set_sub_content (const XPath &xpath, const XS_String &s, bool cdata=false)
 set content of a subnode specified by an XPath expression
XS_String get_trailing () const
bool write (std::ostream &out, const XMLFormat &format, WRITE_MODE mode=FORMAT_SMART, int indent=0) const
 write node with children tree to output stream
int count (const XPath &xpath) const
 count the nodes matching the given relative XPath expression
int count (XPath::const_iterator from, const XPath::const_iterator &to) const
 count the nodes matching the given relative XPath expression
bool filter (const XPath &xpath, XMLNode &target) const
 copy matching tree nodes using the given XPath filter expression
const XMLNodefind_relative (const XPath &xpath) const
 XPath find function (const)
XMLNodefind_relative (const XPath &xpath)
 XPath find function.
XMLNodeget_first_child () const
void assign (const XS_String &s)
void assign (LPCXSSTR s)
void assign (LPCXSSTR s, size_t l)
 operator LPCXSSTR () const
XS_Stringprintf (LPCXSSTR fmt,...)
XS_Stringvprintf (LPCXSSTR fmt, va_list vl)
XS_Stringappendf (LPCXSSTR fmt,...)
XS_Stringvappendf (LPCXSSTR fmt, va_list vl)

Public Attributes

XMLFormat _format
XMLErrorList _errors

Protected Member Functions

XMLNodefilter (XPath::const_iterator from, const XPath::const_iterator &to) const
 create a new node tree using the given XPath filter expression
XMLNodecreate_relative (const XPath &xpath)
 relative XPath create function
void original_write_worker (std::ostream &out) const
 write node with children tree to output stream using original white space
void plain_write_worker (std::ostream &out) const
 print node without any white space
void pretty_write_worker (std::ostream &out, const XMLFormat &format, int indent) const
 pretty print node with children tree to output stream
void smart_write_worker (std::ostream &out, const XMLFormat &format, int indent) const
 write node with children tree to output stream using smart formating

Protected Attributes

Children _children
AttributeMap _attributes
std::string _leading
std::string _content
std::string _end_leading
std::string _trailing
bool _cdata_content

Friends

struct XMLPos
struct const_XMLPos
struct XMLReaderBase
struct XPathElement

Detailed Description

XML document holder.

Definition at line 2933 of file xmlstorage.h.


Member Typedef Documentation

typedef std::string XMLStorage::XS_String::super [inherited]

Definition at line 362 of file xmlstorage.h.


Member Enumeration Documentation

Enumerator:
COPY_NOCHILDREN 

Definition at line 1614 of file xmlstorage.h.


Constructor & Destructor Documentation

XMLStorage::XMLDoc::XMLDoc (  ) [inline]

Definition at line 2935 of file xmlstorage.h.

     :  XMLNode("")
    {
    }
XMLStorage::XMLDoc::XMLDoc ( LPCTSTR  path,
bool  force_utf8 = false 
) [inline]

Definition at line 2940 of file xmlstorage.h.

References read_file().

     :  XMLNode("")
    {
        read_file(path, force_utf8);
    }

Here is the call graph for this function:


Member Function Documentation

void XMLStorage::XMLNode::add_child ( XMLNode child ) [inline, inherited]

add a new child node

Definition at line 1672 of file xmlstorage.h.

References XMLStorage::XMLNode::_children.

Referenced by XMLStorage::XMLPos::add_down(), XMLStorage::XMLPos::create_node_content(), XMLStorage::XMLNode::create_relative(), XMLStorage::XMLNode::filter(), and XMLStorage::XMLNode::subvalue().

    {
        _children.push_back(child);
    }

Here is the caller graph for this function:

XS_String& XMLStorage::XS_String::appendf ( LPCXSSTR  fmt,
  ... 
) [inline, inherited]

Definition at line 464 of file xmlstorage.h.

    {
        va_list vl;

        va_start(vl, fmt);
        vappendf(fmt, vl);
        va_end(vl);

        return *this;
    }
void XMLStorage::XS_String::assign ( const XS_String s ) [inline, inherited]
void XMLStorage::XS_String::assign ( LPCXSSTR  s ) [inline, inherited]

Definition at line 408 of file xmlstorage.h.

void XMLStorage::XS_String::assign ( LPCXSSTR  s,
size_t  l 
) [inline, inherited]

Definition at line 409 of file xmlstorage.h.

{super::assign(s, l);}
void XMLStorage::XMLNode::clear (  ) [inline, inherited]
int XMLStorage::XMLNode::count ( const XPath xpath ) const [inline, inherited]

count the nodes matching the given relative XPath expression

Definition at line 1879 of file xmlstorage.h.

Referenced by XMLStorage::XMLPos::count().

    {
        return count(xpath.begin(), xpath.end());
    }

Here is the caller graph for this function:

int XMLStorage::XMLNode::count ( XPath::const_iterator  from,
const XPath::const_iterator &  to 
) const [inherited]

count the nodes matching the given relative XPath expression

Definition at line 319 of file xmlstorage.cpp.

References XMLStorage::XMLNode::_children, and XMLStorage::XPathElement::matches().

{
    const XPathElement& elem = *from++;
    int cnt = 0;
    int n = 0;

    for(XMLNode::Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
        if (elem.matches(**it, n)) {
            if (from != to)
                 // iterate deeper
                cnt += (*it)->count(from, to);
            else
                 // increment match counter
                ++cnt;
        }

    return cnt;
}

Here is the call graph for this function:

XMLNode * XMLStorage::XMLNode::create_relative ( const XPath xpath ) [protected, inherited]

relative XPath create function

Definition at line 297 of file xmlstorage.cpp.

References XMLStorage::XMLNode::add_child(), and XMLStorage::XMLNode::XMLNode().

Referenced by XMLStorage::XMLPos::create_relative(), and XMLStorage::XMLNode::set_sub_content().

{
    XMLNode* node = this;

    for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
        XMLNode* child = it->find(node);

        if (!child) {
            child = new XMLNode(it->_child_name);
            node->add_child(child);

            for(XPathElement::MAPATTR::const_iterator b=it->_mAttrAndAttr.begin(), e=it->_mAttrAndAttr.end(); b!=e; ++b)
                (*this)[b->first] = b->second;
        }

        node = child;
    }

    return node;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLStorage::XMLNode::erase ( const XS_String attr_name ) [inline, inherited]

remove the attribute 'attr_name'

Definition at line 1724 of file xmlstorage.h.

References XMLStorage::XMLNode::_attributes, and XMLStorage::XS_StringMap::erase().

Referenced by XMLStorage::XMLNode::clear(), XMLStorage::XMLPos::erase(), and XMLStorage::XMLNode::Children::remove().

    {
        _attributes.erase(attr_name);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLStorage::XMLNode::filter ( const XPath xpath,
XMLNode target 
) const [inherited]

copy matching tree nodes using the given XPath filter expression

Definition at line 339 of file xmlstorage.cpp.

References XMLStorage::XMLNode::_attributes, XMLStorage::XMLNode::_children, and XMLStorage::XMLNode::Children::move().

Referenced by XMLStorage::XMLPos::filter(), and XMLStorage::XMLNode::filter().

{
    XMLNode* ret = filter(xpath.begin(), xpath.end());
    if (!ret)
        return false;

     // move returned nodes to target node
    target._children.move(ret->_children);
    target._attributes = ret->_attributes;

    delete ret;

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

XMLNode * XMLStorage::XMLNode::filter ( XPath::const_iterator  from,
const XPath::const_iterator &  to 
) const [protected, inherited]

create a new node tree using the given XPath filter expression

Definition at line 355 of file xmlstorage.cpp.

References XMLStorage::XMLNode::_children, XMLStorage::XMLNode::add_child(), XMLStorage::XMLNode::COPY_NOCHILDREN, XMLStorage::XMLNode::filter(), XMLStorage::XPathElement::matches(), and XMLStorage::XMLNode::XMLNode().

{
    XMLNode* copy = NULL;

    const XPathElement& elem = *from++;
    int cnt = 0;
    int n = 0;

    for(XMLNode::Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
        if (elem.matches(**it, n)) {
            if (!copy)
                copy = new XMLNode(*this, XMLNode::COPY_NOCHILDREN);

            if (from != to) {
                XMLNode* ret = (*it)->filter(from, to);

                if (ret) {
                    copy->add_child(ret);
                    ++cnt;
                }
            } else {
                copy->add_child(new XMLNode(**it, XMLNode::COPY_NOCHILDREN));
                ++cnt;
            }
        }

    if (!cnt) {
        delete copy;
        copy = NULL;
    }

    return copy;
}

Here is the call graph for this function:

XMLNode * XMLStorage::XMLNode::find_relative ( const XPath xpath ) [inherited]

XPath find function.

Definition at line 283 of file xmlstorage.cpp.

{
    XMLNode* node = this;

    for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
        node = it->find(node);

        if (!node)
            break;
    }

    return node;
}
const XMLNode * XMLStorage::XMLNode::find_relative ( const XPath xpath ) const [inherited]

XPath find function (const)

Definition at line 269 of file xmlstorage.cpp.

Referenced by XMLRPC::XMLRPCParser::get_param_type(), XMLStorage::XMLNode::get_sub_content(), XMLStorage::const_XMLPos::go(), and XMLStorage::XMLPos::go().

{
    const XMLNode* node = this;

    for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
        node = it->const_find(node);

        if (!node)
            break;
    }

    return node;
}

Here is the caller graph for this function:

template<typename T >
XS_String XMLStorage::XMLNode::get ( const T &  attr_name,
LPCXSSTR  def = XS_EMPTY_STR 
) const [inline, inherited]

read only access to an attribute

Definition at line 1713 of file xmlstorage.h.

References XMLStorage::XMLNode::_attributes, XMLStorage::XS_StringMap::end(), and XMLStorage::XS_StringMap::find().

Referenced by XMLStorage::const_XMLPos::get(), XMLStorage::XMLPos::get(), XMLStorage::XPathElement::matches(), XMLStorage::const_XMLPos::operator[](), XMLStorage::XMLNode::subvalue(), XMLStorage::XMLBool::XMLBool(), XMLStorage::XMLDouble::XMLDouble(), XMLStorage::XMLInt::XMLInt(), XMLStorage::XMLInt64::XMLInt64(), and XMLStorage::XMLString::XMLString().

    {
        AttributeMap::const_iterator found = _attributes.find(attr_name);

        if (found != _attributes.end())
            return found->second;
        else
            return def;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

const AttributeMap& XMLStorage::XMLNode::get_attributes (  ) const [inline, inherited]

Definition at line 1789 of file xmlstorage.h.

References XMLStorage::XMLNode::_attributes.

    {
        return _attributes;
    }
AttributeMap& XMLStorage::XMLNode::get_attributes (  ) [inline, inherited]

Definition at line 1794 of file xmlstorage.h.

References XMLStorage::XMLNode::_attributes.

    {
        return _attributes;
    }
Children& XMLStorage::XMLNode::get_children (  ) [inline, inherited]

Definition at line 1784 of file xmlstorage.h.

References XMLStorage::XMLNode::_children.

    {
        return _children;
    }
const Children& XMLStorage::XMLNode::get_children (  ) const [inline, inherited]

Definition at line 1779 of file xmlstorage.h.

References XMLStorage::XMLNode::_children.

Referenced by XMLRPC::XMLRPCStruct::XMLRPCStruct().

    {
        return _children;
    }

Here is the caller graph for this function:

XS_String XMLStorage::XMLNode::get_content (  ) const [inline, inherited]

read element node content

Definition at line 1800 of file xmlstorage.h.

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

Referenced by XMLStorage::XMLNode::get_sub_content(), and test_read().

    {
        return DecodeXMLString(_content);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string XMLStorage::XMLNode::get_encoded_content (  ) const [inline, inherited]

read element node content as encoded string

Definition at line 1806 of file xmlstorage.h.

References XMLStorage::XMLNode::_content.

    {
        return _content;
    }
XMLNode* XMLStorage::XMLNode::get_first_child (  ) const [inline, inherited]

Definition at line 1896 of file xmlstorage.h.

References XMLStorage::XMLNode::_children.

Referenced by XMLRPC::XMLRPCParser::get_param_type(), XMLStorage::const_XMLPos::go_down(), and XMLStorage::XMLPos::go_down().

    {
        if (!_children.empty())
            return _children.front();
        else
            return NULL;
    }

Here is the caller graph for this function:

XS_String XMLStorage::XMLNode::get_sub_content ( const XPath xpath ) const [inline, inherited]

read content of a subnode specified by an XPath expression

Definition at line 1812 of file xmlstorage.h.

References XMLStorage::XMLNode::find_relative(), XMLStorage::XMLNode::get_content(), and XS_EMPTY_STR.

Referenced by XMLRPC::XMLRPCStruct::XMLRPCStruct().

    {
        const XMLNode* node = find_relative(xpath);

        if (node)
            return node->get_content();
        else
            return XS_EMPTY_STR;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

XS_String XMLStorage::XMLNode::get_trailing (  ) const [inline, inherited]

Definition at line 1846 of file xmlstorage.h.

References XMLStorage::XMLNode::_trailing, and XMLStorage::DecodeXMLString().

    {
        return DecodeXMLString(_trailing);
    }

Here is the call graph for this function:

XMLStorage::XS_String::operator LPCXSSTR (  ) const [inline, inherited]

Definition at line 411 of file xmlstorage.h.

{return c_str();}
XS_String& XMLStorage::XMLNode::operator[] ( const XS_String attr_name ) [inline, inherited]

index operator write access to an attribute

Definition at line 1697 of file xmlstorage.h.

References XMLStorage::XMLNode::_attributes.

    {
        return _attributes[attr_name];
    }
XS_String XMLStorage::XMLNode::operator[] ( const XS_String attr_name ) const [inline, inherited]

index operator read access to an attribute

Definition at line 1703 of file xmlstorage.h.

References XMLStorage::XMLNode::_attributes, and XMLStorage::XMLNode::AttributeMap::get().

    {
#if defined(UNICODE) && !defined(XS_STRING_UTF8)
        return _attributes.get(((std::string)attr_name).c_str());
#else
        return _attributes.get(attr_name.c_str());
#endif
    }

Here is the call graph for this function:

void XMLStorage::XMLNode::original_write_worker ( std::ostream &  out ) const [protected, inherited]

write node with children tree to output stream using original white space

Definition at line 568 of file xmlstorage.cpp.

References XMLStorage::XMLNode::_attributes, XMLStorage::XMLNode::_children, XMLStorage::XMLNode::_content, XMLStorage::XMLNode::_leading, XMLStorage::XS_StringMap::begin(), XMLStorage::EncodeXMLString(), and XMLStorage::XS_StringMap::end().

Referenced by XMLStorage::XMLNode::write().

{
    out << _leading << '<' << EncodeXMLString(*this);

    for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
        out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";

    if (!_children.empty() || !_content.empty()) {
        out << '>';

        if (_cdata_content)
            out << CDATA_START << _content << CDATA_END;
        else
            out << _content;

        for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
            (*it)->original_write_worker(out);

        out << _end_leading << "</" << EncodeXMLString(*this) << '>';
    } else
        out << "/>";

    out << _trailing;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLStorage::XMLNode::plain_write_worker ( std::ostream &  out ) const [protected, inherited]

print node without any white space

Definition at line 595 of file xmlstorage.cpp.

Referenced by XMLStorage::XMLNode::write().

{
    out << '<' << EncodeXMLString(*this);

    for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
        out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";

     // strip leading white space from content
    const char* content = _content.c_str();
    while(isspace((unsigned char)*content)) ++content;

    if (!_children.empty() || *content) {
        out << ">" << content;

        for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
            (*it)->plain_write_worker(out);

        out << "</" << EncodeXMLString(*this) << ">";
    } else
        out << "/>";
}

Here is the caller graph for this function:

void XMLStorage::XMLNode::pretty_write_worker ( std::ostream &  out,
const XMLFormat format,
int  indent 
) const [protected, inherited]

pretty print node with children tree to output stream

Definition at line 619 of file xmlstorage.cpp.

Referenced by XMLStorage::XMLNode::write().

{
    for(int i=indent; i--; )
        out << XML_INDENT_SPACE;

    out << '<' << EncodeXMLString(*this);

    for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
        out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";

     // strip leading white space from content
    const char* content = _content.c_str();
    while(isspace((unsigned char)*content)) ++content;

    if (!_children.empty() || *content) {
        out << '>' << content;

        if (!_children.empty())
            out << format._endl;

        for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
            (*it)->pretty_write_worker(out, format, indent+1);

        for(int i=indent; i--; )
            out << XML_INDENT_SPACE;

        out << "</" << EncodeXMLString(*this) << '>' << format._endl;
    } else
        out << "/>" << format._endl;
}

Here is the caller graph for this function:

XS_String& XMLStorage::XS_String::printf ( LPCXSSTR  fmt,
  ... 
) [inline, inherited]

Definition at line 423 of file xmlstorage.h.

    {
        va_list vl;

        va_start(vl, fmt);
        vprintf(fmt, vl);
        va_end(vl);

        return *this;
    }
void XMLStorage::XMLNode::put ( const XS_String attr_name,
const XS_String value 
) [inline, inherited]

write access to an attribute

Definition at line 1691 of file xmlstorage.h.

References XMLStorage::XMLNode::_attributes.

Referenced by XMLStorage::XMLPos::put().

    {
        _attributes[attr_name] = value;
    }

Here is the caller graph for this function:

bool XMLStorage::XMLDoc::read ( XMLReaderBase reader,
const std::string &  display_path,
bool  force_utf8 = false 
) [inline]

Definition at line 3007 of file xmlstorage.h.

References XMLStorage::XMLFormat::_endl, _errors, _format, XMLStorage::XMLReaderBase::clear_errors(), XMLStorage::XMLReaderBase::get_endl(), XMLStorage::XMLReaderBase::get_errors(), XMLStorage::XMLReaderBase::get_format(), XMLStorage::XMLReaderBase::read(), and XMLStorage::XMLReaderBase::setSystemId().

Referenced by read_file(), and read_stream().

    {
#ifdef XS_NATIVE
        reader.setSystemId(display_path.c_str());
#elif defiend(XMLNODE_LOCATION)
         // make a string copy to handle temporary string objects
        _display_path = display_path;
        reader._display_path = _display_path.c_str();
#endif

        reader.clear_errors();
        reader.read(force_utf8);

        _format = reader.get_format();
        _format._endl = reader.get_endl();

        if (!reader.get_errors().empty()) {
            _errors = reader.get_errors();
            return false;
        }

        return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLStorage::XMLDoc::read_buffer ( const char *  buffer,
size_t  len,
const std::string &  system_id = std::string(),
bool  force_utf8 = false 
) [inline]

Definition at line 2987 of file xmlstorage.h.

Referenced by XMLStorage::XMLMessageFromString::XMLMessageFromString(), XMLStorage::XMLMessageReader::XMLMessageReader(), and XMLRPC::XMLRPCParser::XMLRPCParser().

    {
        return read_buffer(std::string(buffer, len), system_id, force_utf8);
    }

Here is the caller graph for this function:

bool XMLStorage::XMLDoc::read_buffer ( const std::string &  buffer,
const std::string &  system_id = std::string(),
bool  force_utf8 = false 
) [inline]

Definition at line 2992 of file xmlstorage.h.

References read_stream().

    {
        std::istringstream istr(buffer);

        return read_stream(istr, system_id, force_utf8);
    }

Here is the call graph for this function:

bool XMLStorage::XMLDoc::read_file ( LPCTSTR  path,
bool  force_utf8 = false 
) [inline]

Definition at line 2972 of file xmlstorage.h.

References read(), and XMLStorage::XS_String::XS_String().

Referenced by test_delete(), test_read(), test_read1(), test_read2(), xml_test(), and XMLDoc().

    {
        tifstream in(path);
        if (!in.good())
            return false;

        XMLReader reader(this, in);

#if defined(_STRING_DEFINED) && !defined(XS_STRING_UTF8)
        return read(reader, std::string(ANS(path)), force_utf8);
#else
        return read(reader, XS_String(path), force_utf8);
#endif
    }

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLStorage::XMLDoc::read_stream ( std::istream &  in,
const std::string &  system_id = std::string(),
bool  force_utf8 = false 
) [inline]

Definition at line 2999 of file xmlstorage.h.

References read().

Referenced by read_buffer().

    {
        XMLReader reader(this, in);

        return read(reader, system_id, force_utf8);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLStorage::XMLNode::remove_children ( const XS_String name ) [inline, inherited]

remove all children named 'name'

Definition at line 1678 of file xmlstorage.h.

References XMLStorage::XMLNode::_children.

Referenced by XMLStorage::XMLPos::remove_children().

    {
        Children::iterator it, next=_children.begin();

        while((it=next) != _children.end()) {
            ++next;

            if (**it == name)
                _children.erase(it);
        }
    }

Here is the caller graph for this function:

void XMLStorage::XMLNode::set_content ( const XS_String s,
bool  cdata = false 
) [inline, inherited]

set element node content

Definition at line 1823 of file xmlstorage.h.

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

Referenced by XMLStorage::XMLPos::create_node_content(), and XMLStorage::XMLNode::set_sub_content().

    {
        _content.assign(EncodeXMLString(s.c_str(), cdata));
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLStorage::XMLNode::set_encoded_content ( const std::string &  s ) [inline, inherited]

set element node content from encoded string

Definition at line 1829 of file xmlstorage.h.

References XMLStorage::XMLNode::_content.

    {
        _content.assign(s);
    }
bool XMLStorage::XMLNode::set_sub_content ( const XPath xpath,
const XS_String s,
bool  cdata = false 
) [inline, inherited]

set content of a subnode specified by an XPath expression

Definition at line 1835 of file xmlstorage.h.

References XMLStorage::XMLNode::create_relative(), and XMLStorage::XMLNode::set_content().

    {
        XMLNode* node = create_relative(xpath);

        if (node) {
            node->set_content(s, cdata);
            return true;
        } else
            return false;
    }

Here is the call graph for this function:

void XMLStorage::XMLNode::smart_write_worker ( std::ostream &  out,
const XMLFormat format,
int  indent 
) const [protected, inherited]

write node with children tree to output stream using smart formating

Definition at line 652 of file xmlstorage.cpp.

Referenced by XMLStorage::XMLNode::write().

{
     // strip the first line feed from _leading
    const char* leading = _leading.c_str();
    if (*leading == '\n') ++leading;

    if (!*leading)
        for(int i=indent; i--; )
            out << XML_INDENT_SPACE;
    else
        out << leading;

    out << '<' << EncodeXMLString(*this);

    for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
        out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";

     // strip leading white space from content
    const char* content = _content.c_str();
    while(isspace((unsigned char)*content)) ++content;

    if (_children.empty() && !*content)
        out << "/>";
    else {
        out << '>';

        if (_cdata_content)
            out << CDATA_START << _content << CDATA_END;
        else if (!*content)
            out << format._endl;
        else
            out << content;

        Children::const_iterator it = _children.begin();

        if (it != _children.end()) {
            for(; it!=_children.end(); ++it)
                (*it)->smart_write_worker(out, format, indent+1);

             // strip the first line feed from _end_leading
            const char* end_leading = _end_leading.c_str();
            if (*end_leading == '\n') ++end_leading;

            if (!*end_leading)
                for(int i=indent; i--; )
                    out << XML_INDENT_SPACE;
            else
                out << end_leading;
        } else
            out << _end_leading;

        out << "</" << EncodeXMLString(*this) << '>';
    }

    if (_trailing.empty())
        out << format._endl;
    else
        out << _trailing;
}

Here is the caller graph for this function:

XS_String XMLStorage::XMLNode::subvalue ( const XS_String child_name,
const XS_String attr_name,
int  n = 0 
) const [inline, inherited]

convenient value access in children node

Definition at line 1730 of file xmlstorage.h.

References XMLStorage::XMLNode::get(), XMLStorage::XMLNode::XPathElement, and XMLStorage::XS_String::XS_String().

    {
        const XMLNode* node = XPathElement(child_name, n).const_find(this);

        if (node)
            return node->get(attr_name);
        else
            return XS_String();
    }

Here is the call graph for this function:

XS_String& XMLStorage::XMLNode::subvalue ( const XS_String child_name,
const XS_String attr_name,
int  n = 0 
) [inline, inherited]

convenient storage of distinct values in children node

Definition at line 1741 of file xmlstorage.h.

References XMLStorage::XMLNode::add_child(), XMLStorage::XMLNode::XMLNode(), and XMLStorage::XMLNode::XPathElement.

    {
        XMLNode* node = XPathElement(child_name, n).find(this);

        if (!node) {
            node = new XMLNode(child_name);
            add_child(node);
        }

        return (*node)[attr_name];
    }

Here is the call graph for this function:

XS_String& XMLStorage::XS_String::vappendf ( LPCXSSTR  fmt,
va_list  vl 
) [inline, inherited]

Definition at line 475 of file xmlstorage.h.

References BUFFER_HUGE, BUFFER_LEN, COUNTOF, XS_CHAR, XS_vsnprintf, and XS_vsnprintf_s.

    {
        XS_CHAR b[BUFFER_LEN];

        int l = XS_vsnprintf(b, COUNTOF(b), fmt, vl);

        if (l >= 0)
            super::append(b, l);
        else {
            LPTSTR p = (LPTSTR)malloc(sizeof(TCHAR)*BUFFER_HUGE);

            if (p) {
#ifdef __STDC_WANT_SECURE_LIB__
                l = XS_vsnprintf_s(p, BUFFER_HUGE, _TRUNCATE, fmt, vl);
#else
                l = XS_vsnprintf(p, BUFFER_HUGE, fmt, vl);
#endif
                if (l >= 0)
                    super::append(p, l);
                else
                    super::append(fmt); // snprintf() failed

                free(p);
            } else
                super::append(fmt); // malloc() failed
        }

        return *this;
    }
XS_String& XMLStorage::XS_String::vprintf ( LPCXSSTR  fmt,
va_list  vl 
) [inline, inherited]

Definition at line 434 of file xmlstorage.h.

References BUFFER_HUGE, BUFFER_LEN, COUNTOF, XS_CHAR, XS_vsnprintf, and XS_vsnprintf_s.

    {
        XS_CHAR b[BUFFER_LEN];

        int l = XS_vsnprintf(b, COUNTOF(b), fmt, vl);

        if (l >= 0)
            super::assign(b, l);
        else {
            LPTSTR p = (LPTSTR)malloc(sizeof(TCHAR)*BUFFER_HUGE);

            if (p) {
#ifdef __STDC_WANT_SECURE_LIB__
                l = XS_vsnprintf_s(p, BUFFER_HUGE, _TRUNCATE, fmt, vl);
#else
                l = XS_vsnprintf(p, BUFFER_HUGE, fmt, vl);
#endif
                if (l >= 0)
                    super::assign(p, l);
                else
                    super::assign(fmt); // snprintf() failed

                free(p);
            } else
                super::assign(fmt); // malloc() failed
        }

        return *this;
    }
bool XMLStorage::XMLNode::write ( std::ostream &  out,
const XMLFormat format,
WRITE_MODE  mode = FORMAT_SMART,
int  indent = 0 
) const [inline, inherited]

write node with children tree to output stream

Definition at line 1856 of file xmlstorage.h.

References XMLStorage::FORMAT_ORIGINAL, XMLStorage::FORMAT_PLAIN, XMLStorage::FORMAT_PRETTY, XMLStorage::XMLNode::original_write_worker(), XMLStorage::XMLNode::plain_write_worker(), XMLStorage::XMLNode::pretty_write_worker(), and XMLStorage::XMLNode::smart_write_worker().

    {
        switch(mode) {
          case FORMAT_PLAIN:
            plain_write_worker(out);
            break;

          case FORMAT_PRETTY:
            pretty_write_worker(out, format, indent);
            break;

          case FORMAT_ORIGINAL:
            original_write_worker(out);
            break;

          default:  // FORMAT_SMART
            smart_write_worker(out, format, indent);
        }

        return out.good();
    }

Here is the call graph for this function:

bool XMLStorage::XMLDoc::write ( std::ostream &  out,
WRITE_MODE  mode = FORMAT_SMART 
) const [inline]

write XML stream

Definition at line 3033 of file xmlstorage.h.

References XMLStorage::XMLNode::_children, _format, XMLStorage::FORMAT_PLAIN, and XMLStorage::XMLFormat::print_header().

Referenced by get_html_page(), test_read(), XMLStorage::XMLMessage::toString(), write_file(), and write_formating().

    {
        _format.print_header(out, mode!=FORMAT_PLAIN);

        if (_children.size() == 1)
            _children.front()->write(out, _format, mode);
        else if (!_children.empty()) {
            //throw Exception("more than one XML root!");
            return false;
        }

        return out.good();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLStorage::XMLDoc::write_file ( LPCTSTR  path,
WRITE_MODE  mode = FORMAT_SMART 
) const [inline]

Definition at line 3053 of file xmlstorage.h.

References write().

Referenced by test_delete(), test_read1(), test_read2(), test_write(), and xml_test().

    {
        tofstream out(path);

        return write(out, mode);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLStorage::XMLDoc::write_formating ( LPCTSTR  path ) const [inline]

Definition at line 3060 of file xmlstorage.h.

References write_formating().

    {
        tofstream out(path);

        return write_formating(out);
    }

Here is the call graph for this function:

bool XMLStorage::XMLDoc::write_formating ( std::ostream &  out ) const [inline]

write XML stream with formating

Definition at line 3048 of file xmlstorage.h.

References XMLStorage::FORMAT_PRETTY, and write().

Referenced by write_formating().

    {
        return write(out, FORMAT_PRETTY);
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend struct const_XMLPos [friend, inherited]

Definition at line 1581 of file xmlstorage.h.

friend struct XMLPos [friend, inherited]

Definition at line 1580 of file xmlstorage.h.

friend struct XMLReaderBase [friend, inherited]

Definition at line 1582 of file xmlstorage.h.

friend struct XPathElement [friend, inherited]

Definition at line 1583 of file xmlstorage.h.

Referenced by XMLStorage::XMLNode::subvalue().


Member Data Documentation

bool XMLStorage::XMLNode::_cdata_content [protected, inherited]

Definition at line 1917 of file xmlstorage.h.

Referenced by XMLStorage::XMLNode::operator=().

Children XMLStorage::XMLNode::_children [protected, inherited]
std::string XMLStorage::XMLNode::_content [protected, inherited]
std::string XMLStorage::XMLNode::_end_leading [protected, inherited]

Definition at line 1910 of file xmlstorage.h.

Referenced by XMLStorage::XMLNode::clear(), and XMLStorage::XMLNode::operator=().

Definition at line 3068 of file xmlstorage.h.

Referenced by read(), and xml_test().

Definition at line 3067 of file xmlstorage.h.

Referenced by get_html_page(), read(), and write().

std::string XMLStorage::XMLNode::_leading [protected, inherited]
std::string XMLStorage::XMLNode::_trailing [protected, inherited]

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