C++ tinyxml2::PreviousSibling()














































C++ tinyxml2::PreviousSibling()




The PreviousSibling() of TinyXml2 is used to Navigate to the previous sibling node.

Syntax:-
XMLHandle PreviousSibling()


Example:-


PreviousSibling_demo_file.xml-

<?xml version="1.0"?>

<Root_Element>

       <Child_1>This_is_Child_1_Content_Hello.</Child_1>

<Child_2>This_is_Child_2_Content_Welcome to CppSecrets.com.</Child_2>

</Root_Element>


PreviousSibling.cpp (Filename)-

/*include necessary header files*/
#include <iostream>
#include <cstdlib>
#include "tinyxml2.h"
using namespace std;
using namespace tinyxml2;
 
int main()
{
   
XMLDocument doc;
   
doc.LoadFile(
"PreviousSibling_demo_file.xml");
   
cout
<< " Output : Using PreviousSibling()" << endl;
   
XMLNode* child_1 = doc.LastChild();
   
cout
<< "Last Child of  XML Document is : " << child_1->Value()<< endl;
   
XMLNode* child_2 = child_1->FirstChild();
   
cout
<< "First Child of " << child_1->Value()<< " is: " <<child_2->Value() << endl;
    
XMLNode* child_3 = child_2->NextSibling();
   
cout
<< "Next Sibling of " << child_2->Value()<< " is: " <<child_3->Value() << endl;
 
XMLNode* child_4 = child_3->PreviousSibling();
   
cout
<< "Previous Sibling of " << child_3->Value()<< " is: " <<child_4->Value() << endl;
 
    return 0;
}


Output:-


      



Comments