Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 27th, 2006, 10:50 PM   #1
honeybee
Unverified User
 
Join Date: Dec 2006
Posts: 6
Rep Power: 0 honeybee is on a distinguished road
Question 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
honeybee is offline   Reply With Quote
Old Dec 27th, 2006, 11:06 PM   #2
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
What exactly is your problem? TinyXML is pretty easy to use, is the tutorial not enough?
Game_Ender is offline   Reply With Quote
Old Dec 28th, 2006, 12:54 AM   #3
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
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...
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Dec 28th, 2006, 5:30 AM   #4
honeybee
Unverified User
 
Join Date: Dec 2006
Posts: 6
Rep Power: 0 honeybee is on a distinguished road
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:arse(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
honeybee is offline   Reply With Quote
Old Dec 28th, 2006, 6:03 AM   #5
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 297
Rep Power: 4 Klarre is on a distinguished road
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.
__________________
http://www.klarre.se
Klarre is offline   Reply With Quote
Old Dec 28th, 2006, 9:09 PM   #6
honeybee
Unverified User
 
Join Date: Dec 2006
Posts: 6
Rep Power: 0 honeybee is on a distinguished road
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 is offline   Reply With Quote
Old Dec 29th, 2006, 1:02 AM   #7
honeybee
Unverified User
 
Join Date: Dec 2006
Posts: 6
Rep Power: 0 honeybee is on a distinguished road
Quote:
Originally Posted by honeybee View Post
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?
honeybee is offline   Reply With Quote
Old Dec 29th, 2006, 2:18 AM   #8
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
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.
Game_Ender is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
parsing xml file using tinyxml!! honeybee XML 2 Dec 28th, 2006 11:39 PM
converting string to float beginnerCCC C 22 Oct 2nd, 2006 11:59 PM
OnlineTextEditor.Com! Sane Show Off Your Open Source Projects 43 Jun 16th, 2006 8:55 AM
After execution - Error cannot locate /Skin File? wchar Visual Basic 1 Mar 5th, 2005 9:04 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:46 AM.

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