64 this->deallocateNodes();
66 for(
size_t l_i = 0; l_i < p_xmlNode.
m_nodes.size(); l_i++) {
74 m_nodes.back()->setNext( l_tmpNode);
84 this->deallocateNodes();
88 XmlNode_t::deallocateNodes(
void)
90 for(
size_t l_i = 0; l_i <
m_nodes.size(); l_i++)
112 this->deallocateNodes();
218 return this->
addNode( l_xmlNode);
229 if( l_xmlNode == NULL)
234 if(
m_nodes.empty() ==
false) {
237 m_nodes.back()->setNext( l_xmlNode);
252 m_attributes.push_back( std::make_pair( p_name, p_value));
263 size_t l_index = (*l_it).second;
292 std::pair<MultiMapNodes_t::const_iterator, MultiMapNodes_t::const_iterator> l_itRange;
295 MultiMapNodes_t::const_iterator &l_itFirst = l_itRange.first;
296 MultiMapNodes_t::const_iterator &l_itLast = l_itRange.second;
302 while( l_itFirst != l_itLast) {
304 if( l_index == p_index) {
306 l_resultNode =
m_nodes[ (*l_itFirst).second];
325 for(
size_t l_i = 0; l_i <
m_nodes.size(); l_i++){
328 p_children.push_back(
m_nodes[ l_i]);
337 p_children.push_back(
this);
341 if( p_lazyRelativeMatch ==
true) {
343 for(
size_t l_i = 0; l_i <
m_nodes.size(); l_i++){
345 m_nodes[ l_i]->findSelfOrChildren( p_name, p_children, p_lazyRelativeMatch);
355 p_children.push_back(
this);
357 for(
size_t l_i = 0; l_i <
m_nodes.size(); l_i++){
359 m_nodes[ l_i]->findAny( p_name, p_children);
376 p_ostream <<
"<" << p_xmlNode.
m_name;
379 for(
size_t l_i = 0; l_i < p_xmlNode.
m_attributes.size(); l_i++) {
391 p_ostream << p_xmlNode.
m_text;
393 p_ostream << std::endl;
394 for(
size_t l_i = 0; l_i < p_xmlNode.
m_nodes.size(); l_i++) {
396 p_ostream << *( p_xmlNode.
m_nodes[ l_i]);
404 p_ostream <<
"</" << p_xmlNode.
m_name <<
">" << std::endl;
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);