size_t AXmlElement::_const_find(LIST_AString listPath, AXmlElement::CONST_CONTAINER& result) const { if (isNameEquals(listPath.front())) { listPath.pop_front(); size_t ret = 0; switch(listPath.size()) { case 0: //a_This node is it result.push_back(this); ++ret; break; case 1: { //a_Include immediate children nodes CONTAINER::const_iterator cit = m_Content.begin(); while (cit != m_Content.end()) { // Name only, add if martches if ((*cit)->isNameEquals(listPath.front())) { result.push_back(*cit); ++ret; } ++cit; } } break; default: { //a_Recurse deeper for each element CONTAINER::const_iterator cit = m_Content.begin(); while (cit != m_Content.end()) { if ((*cit)->isNameEquals(listPath.front())) { ret += (*cit)->_const_find(listPath, result); } ++cit; } } break; } return ret; } else return 0; }
size_t AXmlElement::find(const AString& path, AXmlElement::CONST_CONTAINER& result) const { AString strAttribute; AString strPath(path); bool leadingSlash = false; if ('/' == strPath.at(0)) { leadingSlash = true; //a_Signals that slash leads the path so much include current name } //a_Remove the leading name (which should be this element's name) LIST_AString listPath; strPath.split(listPath, '/'); if (leadingSlash) { if (0 == listPath.size()) { //a_ "/" selects current node result.push_back(this); return 1; } else if (0 != listPath.front().compare(m_Name)) { //a_First token MUST be the name of this element if / leads AString str("Absolute path must start with the name of the current root element: root=/"); str.append(m_Name); str.append(" while path="); str.append(path); ATHROW_EX(this, AException::ProgrammingError, str); } } else if (0 == listPath.size()) { //a_ "/" selects current node result.push_back(this); return 1; } else { //a_Relative path implies this node is first listPath.push_front(m_Name); } return _const_find(listPath, result); }