C++ tinyxml2::NoChildren()














































C++ tinyxml2::NoChildren()




NoChildren() returns true if the node has no children.



Syntax:-


bool NoChildren() const


Example:-


Animal.xml:-


<animalList>

 

<animal>

       

<name>Carry</name>

       

<species>Elephant</species>

       

<dateOfBirth>26-01-1999</dateOfBirth>

       

<veterinarianName>Dr. K Stark</veterinarianName>

   

</animal>

</animalList>


NoChildren.cpp (Filename):-

/*include necessary header files*/

#include <iostream>

#include <cstdlib>

#include "tinyxml2.h"

using namespace std;

using namespace tinyxml2;


void checkChildren(tinyxml2::XMLNode* p)

{

    if (p->NoChildren() == 0)

{


      cout << p->Value() << " Has  Children " << endl;

   

}


    else   

{


cout << p->Value() << " Has  No Children " << endl; 


}


}

/* Function to check whether the node has children*/


int main()

{

  

tinyxml2::XMLDocument doc;

   

doc.LoadFile("Animal.xml");

   

cout << " Output : Using NoChildren() function of tinyxml2 " << endl;

   

tinyxml2::XMLNode* animList = doc.FirstChildElement();

   

checkChildren(animList);

   

tinyxml2::XMLNode* anim = animList->FirstChild();

 

checkChildren(anim);


tinyxml2::XMLNode* name = anim->FirstChild();

   

checkChildren(name);

   

tinyxml2::XMLNode* nametext = name->FirstChild();

  

checkChildren(nametext);


return 0;

}


Output:-



Comments