0

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;
}
2
  • Consider using the vcpkg package manager so you can just start using pugixml. The manual approach is to configure include paths and linker dependencies and there are many questions about that. Commented Nov 29, 2023 at 12:35
  • If your are using MinGW use pacman to install pugixml like the VSCode directions told you to install MinGW using pacman: https://packages.msys2.org/package/mingw-w64-ucrt-x86_64-pugixml?repo=ucrt64 you will not have to modify include directories or library directories but you will have to edit your tasks.json to link to this file /ucrt64/lib/libpugixml.a Commented Nov 29, 2023 at 14:15

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.