const AXmlElement *AXmlElement::findElement(const AString& xpath) const { LIST_AString xparts; xpath.split(xparts, '/'); if (xparts.size() > 0) { if ('/' == xpath.at(0)) { if (isNameEquals(xparts.front())) { xparts.pop_front(); if (xparts.size() > 0) return _get(xparts); else return this; } else return NULL; } else { if (xparts.size() > 0) return _get(xparts); else return NULL; } } else { return this; } }
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; }
AXmlElement *AXmlElement::_addElement(const AString& path, bool overwrite, bool insertIntoFront) { if (m_Name.isEmpty()) ATHROW_EX(this, AException::InvalidObject, ASWNL("AXmlElement does not have a name")); LIST_AString xparts; path.split(xparts, '/'); if (!xparts.size()) ATHROW(this, AException::InvalidParameter); //a_Check is absolute is used and if root name matches this element if ('/' == path.at(0) && xparts.size() > 0) { //a_xpath starts with /, make sure names match if (isNameEquals(xparts.front())) xparts.pop_front(); else { AString str("Path specified ("); str.append(path); str.append(") is absolute and does not match this element's name: "); str.append(m_Name); ATHROW_EX(this, AException::InvalidPath, str); } } //a_Skipped over root or relative path specified AXmlElement *p = NULL; if (xparts.size() > 0) { if (overwrite) p = _getOrCreate(xparts, this, insertIntoFront); else p = _createAndAppend(xparts, this, insertIntoFront); } else p = this; return p; }