473 XmlDoc_t::xpath(
const std::string &p_xpath, std::vector< std::string> &p_results,
size_t p_index)
476 std::vector< XmlNode_t *> l_nodeSet[ 2];
477 size_t l_curSetIndex = 0;
482 l_nodeSet[ l_curSetIndex].push_back( &
m_rootNode);
491 if( l_tmpNode == NULL)
498 if( l_nodeSet[ l_curSetIndex].empty() ==
true)
502 std::string l_name, l_xpath;
503 std::string::size_type l_slashPos = 0;
504 std::string::size_type l_nonSlashPos = 0;
505 size_t l_matchCounter = 0;
506 bool l_matchAny =
false;
507 bool l_matchAttribute =
false;
508 bool l_lazyRelativeMatch =
false;
511 if( p_xpath.find(
"/") == 0 && p_xpath.find(
"//") != 0) {
514 l_slashPos = p_xpath.find(
"/", 1);
515 l_name = p_xpath.substr( 1, l_slashPos - 1);
518 for(
size_t l_i = 0; l_i < l_nodeSet[ l_curSetIndex].size(); l_i++) {
520 XmlNode_t *l_tmpNode = l_nodeSet[ l_curSetIndex][ l_i];
523 if( l_name == l_tmpNode->
getName())
524 l_nodeSet[ !l_curSetIndex].push_back( l_tmpNode);
528 l_curSetIndex = !l_curSetIndex;
532 if( l_nodeSet[ l_curSetIndex].empty() ==
true)
543 while( l_slashPos != std::string::npos) {
549 l_lazyRelativeMatch =
false;
552 l_xpath = l_xpath.substr( l_slashPos);
555 if( l_xpath.empty() ==
true)
558 l_slashPos = l_xpath.find(
"/");
560 if( l_slashPos == 0) {
565 if( l_xpath.find(
"//") == 0)
569 l_nonSlashPos = l_xpath.find_first_not_of(
"/");
573 if( l_nonSlashPos == std::string::npos)
577 l_slashPos = l_xpath.find(
"/", l_nonSlashPos);
580 l_name = l_xpath.substr( l_nonSlashPos, l_slashPos - l_nonSlashPos);
587 l_name = l_xpath.substr( 0, l_slashPos);
592 l_lazyRelativeMatch =
true;
599 if( l_name.empty() ==
true)
603 if( l_name[ 0] ==
'@') {
606 l_matchAttribute =
true;
608 l_name = l_name.substr( 1);
617 l_nodeSet[ !l_curSetIndex].clear();
619 for(
size_t l_i = 0; l_i < l_nodeSet[ l_curSetIndex].size(); l_i++) {
621 XmlNode_t *l_tmpNode = l_nodeSet[ l_curSetIndex][ l_i];
624 if( l_matchAny ==
true)
625 l_tmpNode->
findAny( l_name, l_nodeSet[ !l_curSetIndex]);
627 else if( l_lazyRelativeMatch ==
true)
628 l_tmpNode->
findSelfOrChildren( l_name, l_nodeSet[ !l_curSetIndex], l_lazyRelativeMatch);
635 l_curSetIndex = !l_curSetIndex;
638 if( l_nodeSet[ l_curSetIndex].empty() ==
true)
644 for(
size_t l_i = 0; l_i < l_nodeSet[ l_curSetIndex].size(); l_i++) {
646 XmlNode_t *l_tmpNode = l_nodeSet[ l_curSetIndex][ l_i];
651 if( p_index == 0 || ( l_i == ( p_index - 1))) {
653 if( l_matchAttribute ==
false) {
655 p_results.push_back( l_tmpNode->
getText());
658 std::string l_tmpAttr;
659 if( l_tmpNode->
getAttribute( l_name, l_tmpAttr) ==
true)
660 p_results.push_back( l_tmpAttr);
666 return ( p_results.empty() ==
false);