Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   parsing an XML file using C++ library tinyxml! (http://www.programmingforums.org/showthread.php?t=12274)

honeybee Dec 27th, 2006 11:50 PM

parsing an XML file using C++ library tinyxml!
 
Hi all,
I am working with c++ and new to XML. I have a work with TinyXML. I have understood classes and functions of tinyxml. I want to parse my XML file which is like this:

<?xml version="1.0" encoding="utf-8"?>
<users source="URL" challenge="EncodedString" session="String">
<user name="ABC" password="abc" ></user>
<user name="XYZ" password="xyz" ></user>
<source level=""> URL </source>
</users>

I want to parse this xml file using tinyxml so that related data can be transferred to database.

Kindly help
regards

Game_Ender Dec 28th, 2006 12:06 AM

What exactly is your problem? TinyXML is pretty easy to use, is the tutorial not enough?

bl00dninja Dec 28th, 2006 1:54 AM

i have to parse xml files for a school project i'm doing, actually not very difficult w/o libraries due to xml's nice file layout. although, i assume there's probably some way to write shitty xml...

honeybee Dec 28th, 2006 6:30 AM

Thanx for ur replies,

I learned some documentation from net and from this link http://www.gamasutra.com/features/20...uerig_01.shtml I found, how to parse XML file using tinyxml. But just to confirm that if I follow that example and write this:

class Login
{
public:
void Parse(TiXmlHandle handle);

protected:
string m_name;
string m_password;
};

void Login::Parse(TiXmlHandle handle)
{
TiXmlElement* section;

section = handle.FirstChildElement( "user" ).Element();
section->QueryFloatAttribute( "name" , &m_name);
section->QueryFloatAttribute( "password" , &m_password);
}

Then it will store the name and password string in m_name and m_password respectively??

Thanx for ur co-operation!
regards

Klarre Dec 28th, 2006 7:03 AM

Due to the name of the function (QueryFloatAttribute) it feels like it queries a float attribute. There might be a function for quering strings though. Otherwise you can check out the Attribute(const char*) function. It returns a const char* for you.

A tip is to use the debugger to see if variables have gotten the correct values. Another good way is to use std::cout or printf.

honeybee Dec 28th, 2006 10:09 PM

yes!!
Actually I directly copied the snippet so forgot to change that. There is another function QueryValueAttribute..I think it would be useful in this case.

Thanks a lot for ur concern!
regards

honeybee Dec 29th, 2006 2:02 AM

Quote:

Originally Posted by honeybee (Post 121838)
Actually I directly copied the snippet so forgot to change that. There is another function QueryValueAttribute..I think it would be useful in this case.

http://cvs.hep.ucl.ac.uk/viewcvs/esp...meter&rev=HEAD in this link it is mentioned “#ifdef TIXML_USE_STL” then you can use QueryValueAttribute which is used to parse string. And I don't want to use STL!! So how to do this?

Game_Ender Dec 29th, 2006 3:18 AM

It depends on how you compile TinyXML, if you don't want TinyXML to use std::string then just don't define TIXML_USE_STL anywhere its that simple. If you read the documentation I linked to you would see that. All methods that say they take a std::string will take a const char* if you don't define TIXML_USE_STL.


All times are GMT -5. The time now is 1:18 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC