Jump to content

View more

Image of the Day

The beast has a mighty searchlight of evil! #screenshotsaturday https://t.co/bzKepOojDL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

XML Assistance

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 XwingVmanX   Members   

108
Like
0Likes
Like

Posted 01 August 2012 - 04:35 PM

Can anyone point me in the right direction to learn about reading XML files using C++. I was able to find and learn how to write onto/create an xml document, but I am having trouble find information on accessing the xml document.

This is currently what I have

patientList.open("Patients.xml", ios::in);

while(!patientList.fail() && strcmp(user, name))

{
getline(patientList, str);
posOpen = str.find("<name>");
newStr = str.substr(posOpen + 1);
posClose = newStr.find("</name>");
newStr = str.substr(posOpen + 1, posClose);

strcpy(name, newStr.c_str());
}

patientList.close();

Right now I have it going through the XML file, line by line trying to find a name. Now that works fine, but what I want to do next is once the name I am looking for is found I want to grab the line after it.

The XML looks like this

<patient>
<name>Ken</name>
<mood>Happy</mood>
</patient>
<patient>
<name>Bob</name>
<mood>Sad</mood>
</patient>
<patient>
<name>Mike</name>
<mood>Scared</mood>
</patient>

So I want to find the name I am looking for then grab the mood associated with that name.

Thanks for your help in advance.

#2 Adam_42   Members   

3588
Like
1Likes
Like

Posted 01 August 2012 - 05:16 PM

I'd highly recommend using a library like this one instead of parsing it yourself.

#3 XwingVmanX   Members   

108
Like
0Likes
Like

Posted 01 August 2012 - 05:32 PM

Thanks I'll take a look

#4 sungupta   Members   

103
Like
0Likes
Like

Posted 20 August 2012 - 09:16 AM

take a look at liquid xml c++ tool, it will actually output c++ code from your xml, still its better to do it yourself because thats the only way but it should certainly help you understand how to structure your code.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.