#include <xmlstorage.h>

Public Types | |
| typedef XS_StringMap | MAPATTR |
Public Member Functions | |
| XPathElement () | |
| XPathElement (const XS_String &child_name, int child_idx=-1) | |
| XPathElement (const XS_String &child_name, int child_idx, const XS_String &attr_name, const XS_String &attr_value) | |
| LPCXSSTR | parse (LPCXSSTR path) |
| XMLNode * | find (XMLNode *node) const |
| const XMLNode * | const_find (const XMLNode *node) const |
| bool | matches (const XMLNode &node, int &n) const |
Public Attributes | |
| XS_String | _child_name |
| int | _child_idx |
| MAPATTR | _mAttrAndAttr |
Definition at line 1413 of file xmlstorage.h.
Definition at line 1431 of file xmlstorage.h.
| XMLStorage::XPathElement::XPathElement | ( | ) | [inline] |
Definition at line 1415 of file xmlstorage.h.
: _child_idx(-1) {}
| XMLStorage::XPathElement::XPathElement | ( | const XS_String & | child_name, |
| int | child_idx = -1 |
||
| ) | [inline] |
Definition at line 1417 of file xmlstorage.h.
: _child_name(child_name), _child_idx(child_idx) { }
| XMLStorage::XPathElement::XPathElement | ( | const XS_String & | child_name, |
| int | child_idx, | ||
| const XS_String & | attr_name, | ||
| const XS_String & | attr_value | ||
| ) | [inline] |
Definition at line 1422 of file xmlstorage.h.
References _mAttrAndAttr.
: _child_name(child_name), _child_idx(child_idx) { _mAttrAndAttr[attr_name] = attr_value; }
Definition at line 213 of file xmlstorage.cpp.
References XMLStorage::XMLNode::_children, and matches().
Referenced by XMLStorage::const_XMLPos::go_down(), and XMLStorage::const_XMLPos::iterate().
{
int n = 0;
for(XMLNode::Children::const_iterator it=node->_children.begin(); it!=node->_children.end(); ++it)
if (matches(**it, n))
return *it;
return NULL;
}


Definition at line 202 of file xmlstorage.cpp.
References XMLStorage::XMLNode::_children, and matches().
Referenced by XMLStorage::XMLPos::go_down(), XMLStorage::XMLPos::iterate(), and XMLStorage::XMLPos::smart_create().
{
int n = 0;
for(XMLNode::Children::const_iterator it=node->_children.begin(); it!=node->_children.end(); ++it)
if (matches(**it, n))
return *it;
return NULL;
}


| bool XMLStorage::XPathElement::matches | ( | const XMLNode & | node, |
| int & | n | ||
| ) | const |
Definition at line 224 of file xmlstorage.cpp.
References _child_idx, _child_name, _mAttrAndAttr, XMLStorage::XS_StringMap::begin(), XMLStorage::XS_StringMap::end(), XMLStorage::XMLNode::get(), and XS_TEXT.
Referenced by const_find(), XMLStorage::XMLNode::count(), XMLStorage::XMLNode::filter(), XMLStorage::XMLStreamReader::find(), and find().
{
if (node != _child_name)
if (_child_name != XS_TEXT("*")) // use asterisk as wildcard
return false;
for(MAPATTR::const_iterator b=_mAttrAndAttr.begin(), e=_mAttrAndAttr.end(); b!=e; ++b)
if (node.get(b->first) != b->second)
return false;
if (_child_idx == -1)
return true;
else if (n++ == _child_idx)
return true;
else
return false;
}


| LPCXSSTR XMLStorage::XPathElement::parse | ( | LPCXSSTR | path ) |
Definition at line 139 of file xmlstorage.cpp.
References _child_idx, _child_name, XMLStorage::_istspace(), _mAttrAndAttr, _tcschr, _tcslen, _tcsnicmp, _ttoi, XMLStorage::XS_String::assign(), LPCXSSTR, TEXT, XMLStorage::unescape(), and XS_TEXT.
Referenced by XMLStorage::XPath::init().
{
LPCXSSTR slash = _tcschr(path, '/');
if (slash == path)
return NULL;
// parse relative path
size_t l = slash? slash-path: _tcslen(path);
XS_String comp(path, l);
path += l;
// look for [n] and [@attr_name="attr_value"] expressions in path components
LPCXSSTR bracket = _tcschr(comp.c_str(), TEXT('['));
l = bracket? bracket-comp.c_str(): comp.length();
_child_name.assign(comp.c_str(), l);
if (bracket) {
XS_String expr = unescape(bracket, TEXT('['), TEXT(']'));
LPCXSSTR p = expr.c_str();
while(_istspace((_TUCHAR)*p)) ++p;
if (isdigit(*p)) {
int n = _ttoi(p); // read index number
if (n)
_child_idx = n - 1; // convert into zero based index
} else {
while(*p == '@') {
LPCXSSTR equal = _tcschr(++p, '=');
if (equal) {
// look for delimiters
//TODO If there is neither an opening nor a closing delimiter, we should look for white space as delimiter.
LPCXSSTR del1 = equal+1;
LPCXSSTR del2 = *del1==TEXT('\'')||*del1==TEXT('"')? _tcschr(del1+1, *del1): NULL;
// read attribute name and value
const XS_String& attrName = unescape(p, equal-p);
const XS_String& attrValue = del2? unescape(del1, ++del2-del1): unescape(del1);
_mAttrAndAttr[attrName] = attrValue;
if (!del2)
break;
p = del2 + 1;
while(isspace((unsigned char)*p)) ++p;
// handle [@attr1="value1" and @attr2="value2"] expressions
// handle expressions like [@name="1.2" and @profil="IPE" and @date="2006_07"]
if (!_tcsnicmp(p, XS_TEXT("and "), 4))
p += 4;
}
while(_istspace((_TUCHAR)*p)) ++p;
}
}
}
return path;
}


Definition at line 1429 of file xmlstorage.h.
Definition at line 1428 of file xmlstorage.h.
Referenced by XMLStorage::XMLStreamReader::find(), matches(), and parse().
Definition at line 1432 of file xmlstorage.h.
Referenced by matches(), parse(), and XPathElement().
1.7.2