Sign in to follow this  

XML Assistance

This topic is 1946 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
take a look at [url="http://www.liquid-technologies.com/xmldatabinding/xml-schema-to-cpp.aspx"]liquid xml c++ tool[/url], 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.

Share this post


Link to post
Share on other sites

This topic is 1946 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this