Elijah Eisenman
Elijah Eisenman

Reputation: 1

pugixml intergration in visual studio code

am trying to read an xml file in visual studio using the pugixml parser. i have downloaded the parser. but am wondering how i can link it with my c++ code. like how to configure the include directories.here is my code

#include "pugixml.hpp"

#include <iostream>
using namespace std;


int main()
{
    pugi::xml_document doc;
    doc.load_file("XML.xml");           //Load xml file


    pugi::xml_node  efruit = doc.first_child().child("fruit");                //get the child fruit of first child of a xml document i.e file 

    while (efruit != NULL)
    {
        pugi::xml_node fName = efruit.child("name");                      //get the name child of fruit 



        if (fName != NULL)
        {
            cout << fName.text().get();                                  //print the name of fruit i.e text of name
        }


        pugi::xml_node fColor = efruit.child("color");                     //get the color child of fruit

        if (fColor != NULL)
        {
            cout << "  " << fColor.text().get();                        //print the color of fruit i.e text of color
        }
        cout << endl;
        efruit = efruit.next_sibling("fruit");                            //get the sibling of fruit i.e next fruit
    }
    return 0;
}

Upvotes: 0

Views: 296

Answers (1)

Sergio
Sergio

Reputation: 941

The easiest way to use pugixml is to add the source code directly between the files in your project. Download pugixml, unzip it, copy the files contained in the src directory (pugixml.hpp, pugixonfig.hpp and pugixml cpp) to your project directory, add the above files to your project and then compile it.

Upvotes: 1

Related Questions