• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

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
0
tantormedia
Asked:
tantormedia
  • 3
  • 3
1 Solution
 
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
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now