예제 #1
0
 XMLNodeList XMLNode::Path(const std::string& path) {
   XMLNodeList res;
   std::string::size_type name_s = 0;
   std::string::size_type name_e = path.find('/', name_s);
   if (name_e == std::string::npos)
     name_e = path.length();
   res.push_back(*this);
   for (;;) {
     if (res.size() <= 0)
       return res;
     XMLNodeList::iterator node = res.begin();
     std::string node_name = path.substr(name_s, name_e - name_s);
     int nodes_num = res.size();
     for (int n = 0; n < nodes_num; ++n) {
       for (int cn = 0;; ++cn) {
         XMLNode cnode = (*node).Child(cn);
         if (!cnode)
           break;
         if (MatchXMLName(cnode, node_name))
           res.push_back(cnode);
       }
       ++node;
     }
     res.erase(res.begin(), node);
     if (name_e >= path.length())
       break;
     name_s = name_e + 1;
     name_e = path.find('/', name_s);
     if (name_e == std::string::npos)
       name_e = path.length();
   }
   return res;
 }
예제 #2
0
const XMLNodeList & XMLNode::children(const string &n) const {
	if(n.empty()) {
		if(nodelist.empty()) throw xmlerror(xml_childlist_empty);  
		return nodelist;
	}
   
	static XMLNodeList ret;
	ret.clear();
	XMLNodeListConstIterator it;
	
	for(it=nodelist.begin(); it!=nodelist.end(); it++) {	
		if((*it)->name()==n) ret.push_back(*it);
	}
	
	if(ret.empty()) throw xmlerror(xml_name_not_found, n);
   return ret;
}