Hello there forum,
After a pretty thorough C++ course I've tried my hands at coding an actual project but have stumbled on a pretty big problem and here I am asking for your help.
What I'm trying to make right now is a class which communicates with a gameserver through a slightly modified XML-RPC and the problem arises when trying to handle the incoming responses.
These responses are nicely structured in XML format so getting the actual value isn't too hard but storing it in a more elegant way after receiving the response is.
A response can look like this:
<?xml version="1.0"?> <methodResponse> <params> <param> <value><string>South Dakota</string></value> </param> </params> </methodResponse>
Where the value can be one of 4 simple values: int, double, string, boolean
or a struct or array like:
<array> <data> <value><i4>12</i4></value> <value><string>Egypt</string></value> <value><boolean>0</boolean></value> <value><i4>-31</i4></value> </data> </array>
<struct> <member> <name>lowerBound</name> <value><i4>18</i4></value> </member> <member> <name>upperBound</name> <value><i4>139</i4></value> </member> </struct>
Wherein each <value> can be another array or struct.
Now what I'd like to do is read the complete response, parse it and return an object for which it's easy (intuitive) to retrieve a certain value from the response.
So far the best thing I've come up with it is saving all the actual values (that is int, string, double, boolean) in a vector in the class and returning only the structure which references to the vector. However I haven't been able to think of a proper way to store this 'structure'.
So my question to you comes down to this:
Do you know a good way to parse the XML response such that all end-values (int, string, double, boolean) are intuitively accessible while keeping the ability to nest array's and struct's?