mfc: Reading from xml

Dear experts,

I have an xml file on internet containing few key/value pairs. Could you please refer me to any example how I can read those values from the web site in my mfc application?

Thanks,
Dmitriy
tantormediaAsked:
Who is Participating?
 
jkrCommented:
Well, if that is "read a XML file downloaded from the internet" - yes. Regarding how to traverse the document and read specific nodes only, see th edocs at http://www.grinninglizard.com/tinyxmldocs/index.html
TiXmlElement* root = document.FirstChildElement( "Document" );
if ( root )
{
	TiXmlElement* element = root->FirstChildElement( "Element" );
	if ( element )
	{
		TiXmlElement* child = element->FirstChildElement( "Child" );
		if ( child )
		{
			TiXmlElement* child2 = child->NextSiblingElement( "Child" );
			if ( child2 )
			{
				// Finally do something useful.

//...

Open in new window

0
 
jkrCommented:
I'd recommend TinyXML (http://www.grinninglizard.com/tinyxml/) for that purpose, since it's free, lightweight and easy to use. See http://www.grinninglizard.com/tinyxmldocs/tutorial0.html on how to use it.
0
 
tantormediaAuthor Commented:
Thank you for your answer.
Could you please tell me if TinyXML can read xml from internet?
Also, I could not find an example how to read not all elements of the document, but random elements, their attributes etc. Is it possible with TinyXml?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
tantormediaAuthor Commented:
Thank you for the hint. Maybe you could tell me why root can be null?
0
 
jkrCommented:
Well, the XML file could either be completely malformed or simply contain nothing at all.
0
 
tantormediaAuthor Commented:
It worked when I removed paramenters from FirstChildElement() and NextSiblingElement().
Thank you very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.