PugiXML Parsing

Hey all, I am new to the forums! Anyways, I had a few questions regarding how to properly parse XML using PuigXML on C++. I am developing a game, and I have some xml data that I need to be able to access and change values on the fly. I have done hours and hours of research, and haven't come up with anything! Here is an example of the XML I wish to parse.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<Accounts>

	<User>
		<Balance>50</Balance>
		<Creditscore>600</Creditscore>
	</User>
		<Balance>5432</Balance>
		<Creditscore>656</Creditscore>	
	<User>
		<Balance>50</Balance>
		<Creditscore>234</Creditscore>	
	</User>

</Accounts>


That is just an example of the xml. I have tried using XPATH, such as "/Accounts/User/Balance", but this doesnt know which user to select. I have also tried using /Accounts/User[Which user to select]/Balance, but I cannot input a variable into the xpath. Lastly, I need to have a manageable way to properly edit the data and resave the file later. All of this should support a dynamic number of entries, since there is a question as to how many users will be present. Thanks, Drew.

I have also tried the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <pugixml.hpp>

#include <iostream>

const char* xml = "same data as above";

int main()
{

    const std::string path = "/Accounts/User/Balance";

    pugi::xml_parse_result result;

    pugi::xml_document doc;

    doc.load(xml);

    const pugi::xpath_node_set nodes = doc.select_nodes(path.c_str());

    for(auto& node: nodes)
    {
        std::cout << node.node().name() << '\n';
    }
}
Duplicate of http://www.cplusplus.com/forum/beginner/230654/ .

Please don't post multiple threads for the same topic.
Topic archived. No new replies allowed.