![]() |
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 |
What exactly is your problem? TinyXML is pretty easy to use, is the tutorial not enough?
|
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...
|
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 |
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. |
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 |
Quote:
|
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