1

for example:

<something>
   <x/>
   <x/>
   <y/>
   <z/>
</something>

It must return 2, I thought about using, for this example:

int Get_total_x(){
   int total=0;
   for(xml_node<> *x=root_node->first_node("x"); x; x=x->next_sibling()){
      total++;
   };
   return total;
};

Does RapidXML has a especific function for that?

2 Answers2

0

I am not familiar with rapidxml anyway I just gone through the code and I found

inline std::size_t count_children(xml_node<Ch> *node)

in rapidxml_utils.hpp

Gilson PJ
  • 3,443
  • 3
  • 32
  • 53
  • Tanks, but that returns me the ammount of all the children inside the node, in my xml doc i not only have x, also i have y and z for example, i only want those who match with my search (x). – Roberto Jaimes Mar 26 '16 at 21:07
  • can u provide a sample xml file that you are trying to parse? – Gilson PJ Mar 26 '16 at 21:16
  • I edited the post whit a example.of what i am trying to do. – Roberto Jaimes Mar 28 '16 at 04:50
  • there is no y & z children in the example and am sure `cout_children` will work for you if it was the xml format – Gilson PJ Mar 28 '16 at 05:17
  • I edited the post again, as you can see, there is **four child nodes** but only **two are x** that are what i am searching, `count_children()` will return me four. – Roberto Jaimes Mar 28 '16 at 17:02
0

Your xml file section, I presume, is not valid: the <x>, <x>, <y>, <z> elements aren't closed and are not empty. You should write <x/>, <x/>, <y/>, <z/>

Sergio
  • 891
  • 9
  • 27