943,660 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3927
  • C++ RSS
Nov 22nd, 2008
0

Convert xmlChar to int

Expand Post »
Hey people, i am having the next easy problem but i dont find any answer on how to do that:
Im using libxml2 to read a XML file, in one part of my code i need to compare two attributes from different nodes which are numbers (1,2,3,4,5,6...). The problem is when i say "if (x == y) {}" it always pass it because cant compare xmlChars (at least thats what i think).
Im looking for some easy method to convert those values to int so i can do a comparission and solve the problem.
Thank you in advance!

the code:
C++ Syntax (Toggle Plain Text)
  1. for (resource; resource != NULL; resource = resource->next)
  2. {
  3. xmlChar *resource_id;
  4. resource_id = xmlGetProp (resource, (const xmlChar *)"ID");
  5. for (event; event != NULL; event = event->next)
  6. {
  7. xmlChar *event_id;
  8. // event_id = xmlGetProp (event, (const xmlChar *)"ID");
  9. x = xmlGetProp (event "ID");
  10.  
  11. if (resource_id == event_id)
  12. {
  13. std::cout << "parada 1" << std::endl;
  14. }
  15. }
  16. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fedderico10 is offline Offline
11 posts
since Jan 2008
Nov 22nd, 2008
0

Re: Convert xmlChar to int

You want to use
C++ Syntax (Toggle Plain Text)
  1. xmlStrEqual(resource_id, event_id)

it will return 1 if equal and 0 if different.

so

C++ Syntax (Toggle Plain Text)
  1. if(xmlStrEqual(resource_id, event_id))
  2. std::cout << "parada 1" << std::endl;

should do the trick.

http://xmlsoft.org/html/libxml-xmlst...ml#xmlStrEqual

also resource_id == event_id does not work since you are just comparing two addresses, not what the values are at the addresses your looking at.
Last edited by Paul.Esson; Nov 22nd, 2008 at 7:35 pm.
Reputation Points: 21
Solved Threads: 10
Junior Poster
Paul.Esson is offline Offline
181 posts
since Feb 2005
Nov 22nd, 2008
0

Re: Convert xmlChar to int

As far as I know there is
  1. int xmlStrEqual(const xmlChar * str1,
  2. const xmlChar * str2)
function in xmlstring module (and other xmlChar string handling functions). For example, you can convert xml-string to ordinar C-string then use atol to get integer value of attribute - and so on...

I don't use libxml now then can't present ready-to-use code. Look at libxml2 manual...
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Nov 22nd, 2008
0

Re: Convert xmlChar to int

Click to Expand / Collapse  Quote originally posted by ArkM ...
As far as I know there is
  1. int xmlStrEqual(const xmlChar * str1,
  2. const xmlChar * str2)
function in xmlstring module (and other xmlChar string handling functions). For example, you can convert xml-string to ordinar C-string then use atol to get integer value of attribute - and so on...

I don't use libxml now then can't present ready-to-use code. Look at libxml2 manual...
Yea, There is hence the reason I posted about it 58 minutes ago
Last edited by Paul.Esson; Nov 22nd, 2008 at 8:28 pm.
Reputation Points: 21
Solved Threads: 10
Junior Poster
Paul.Esson is offline Offline
181 posts
since Feb 2005
Nov 23rd, 2008
0

Re: Convert xmlChar to int

Yes that way i can compare to strings but what if i need to compare a string with an integer? how would i do that?
Thanks anyway!
Last edited by fedderico10; Nov 23rd, 2008 at 5:20 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fedderico10 is offline Offline
11 posts
since Jan 2008
Nov 23rd, 2008
0

Re: Convert xmlChar to int

I found this thread on the xml gnome mailing list that may be of help. It does appear that there is nothing similar to atoint for an xmlChar *, but I guess you can do it the way that this guy describes or alternatively format a char* from your number (using sscanf) then create a xmlChar* from that then compare those two strings.

Post I found is http://mail.gnome.org/archives/xml/2.../msg00060.html
Reputation Points: 21
Solved Threads: 10
Junior Poster
Paul.Esson is offline Offline
181 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: g++ error?
Next Thread in C++ Forum Timeline: Simple circular bit shifts, in C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC