Reading XML Stream in C++

M

Mayur

Hello All,

My code below sending request to web server and getting response as XML
string.
char* response;
wf.getResponse(response,500);

where outout of above function returns xml string which is stored in
response variable.

response ="<login>
<session_id>50e39f252f247cc8e4ebb40416f16c38</session_id>
<logged_in>TRUE</logged_in>
<voice_enabled>TRUE</voice_enabled>
<ads_disabled>TRUE</ads_disabled>
<user_id>97558</user_id>
-
- <buddy_list>
<user_id>97002</user_id>
<username>unicorn11</username>
<logged_in>FALSE</logged_in>
<game_id>0</game_id>
<user_id>97562</user_id>
<username>yashwant</username>
<logged_in>FALSE</logged_in>
<game_id>0</game_id>
</buddy_list>
<auto_join_channel />
<button_config />
</login>";

I need to parse this string so that i can check output where user is logged
in whats game ID and all these parameter i required to manuoulate
my task.

where i implemeneted this in c# using XmlTextReader which is so simple but i
need it in unmanaged c++ application..


so please help me regarding this....
wating for reply.
Mayur
 
W

William DePalo [MVP VC++]

Mayur said:
response ="<login>
<session_id>50e39f252f247cc8e4ebb40416f16c38</session_id>
<logged_in>TRUE</logged_in>
<voice_enabled>TRUE</voice_enabled>
<ads_disabled>TRUE</ads_disabled>
<user_id>97558</user_id>
...
</login>";

I need to parse this string so that i can check output where user is
logged in whats game ID and all these parameter i required to manuoulate
my task.

where i implemeneted this in c# using XmlTextReader which is so simple but
i need it in unmanaged c++ application..

Microsoft supplies a COM component called MSXML that can do that. If you
don't have the latest version you should be able to find it here:

http://msdn.microsoft.com/XML/XMLDownloads/

If you want to use it you "import" it into your source and the compiler will
generate header files from the component's type library.

Alternatively, you can find any of a number of hand-rolled C++ wrappers,
e.g.,

http://www.codeguru.com/cpp/data/data-misc/xml/article.php/c4575/

http://www.codeproject.com/soap/msxmlcpp.asp

though I should tell you that I know nothing of the classes in the last two
links except that they came up first in a search.

Regards,
Will
 
S

Steve Alpert

Mayur said:
Hello All,

My code below sending request to web server and getting response as XML
string.
char* response;
wf.getResponse(response,500);

where outout of above function returns xml string which is stored in
response variable.

response ="<login>
<session_id>50e39f252f247cc8e4ebb40416f16c38</session_id>
<logged_in>TRUE</logged_in>
<voice_enabled>TRUE</voice_enabled>
<ads_disabled>TRUE</ads_disabled>
<user_id>97558</user_id>
-
- <buddy_list>
<user_id>97002</user_id>
<username>unicorn11</username>
<logged_in>FALSE</logged_in>
<game_id>0</game_id>
<user_id>97562</user_id>
<username>yashwant</username>
<logged_in>FALSE</logged_in>
<game_id>0</game_id>
</buddy_list>
<auto_join_channel />
<button_config />
</login>";

I need to parse this string so that i can check output where user is logged
in whats game ID and all these parameter i required to manuoulate
my task.

where i implemeneted this in c# using XmlTextReader which is so simple but i
need it in unmanaged c++ application..

Mayur:

I had a similar requirement and got back a similar xml string. Rather than go
through the hassle of using xml to process it, I wrote a simple function:
char * get_string(char *msg, char *pfx, char *sfx)
that looked for pfx in msg. If it found it, it looked for sfx after that point
and returned an allocated string of what was between. Worked like a charm.
It returns NULL if it can't find anything.

char *gameid = get_string(msg, "<game_id>", "</game_id>");

cheers!
/steveA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top