C++ tinyxml2::Next()














































C++ tinyxml2::Next()




Next() returns the next attribute in the list.



Syntax:-


const XMLAttribute* Next() const


Example:-


Book.xml:-


<?xml version="1.0"?>

<catalog>

   

<book id="bk101" edition="6th edition">

       

<author fName="Gambardella"  mName="Vijay" lName= "Matthew" />

<title>XML Developer's Guide</title>

       

<genre>Computer</genre>

       

<publish_date>2000-10-01</publish_date>

</book>

</catalog>


Next.cpp (Filename):-

/*include necessary header files*/

#include <iostream>

#include <cstdlib>

#include "tinyxml2.h"

using namespace std;


using namespace tinyxml2;


 int main()

{

   

XMLDocument xmlDocument;

    

xmlDocument.LoadFile("Book.xml");

    

cout << "\n Output : Using Next() function of tinyxml2 " << endl;

    

XMLNode* book_info = xmlDocument.FirstChildElement();

    

XMLNode* book1 = book_info->FirstChildElement();

    

XMLElement* bk1 = book1->ToElement();


XMLNode* author1 = book1->FirstChild();

    

cout << "\n\t Book Id is : "<< bk1->FirstAttribute()->Value() << endl;

    

/*This will Print First Attribute value of Book element*/

   

const tinyxml2::XMLAttribute* mName1 = author1->ToElement()->FirstAttribute()->Next();

    

cout << "\n\t Author Name : "<< author1->ToElement()->FirstAttribute()->Value() << "   " << mName1->Value() << "   " << author1->ToElement()->Attribute("lName") << endl << endl;

    

return 0;


}


Output:-



Comments