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:

for (resource; resource != NULL; resource = resource->next)
		{
		xmlChar *resource_id;
		resource_id = xmlGetProp (resource, (const xmlChar *)"ID");
		for (event; event != NULL; event = event->next)
			{
			xmlChar *event_id;
// 			event_id = xmlGetProp (event, (const xmlChar *)"ID");
			x = xmlGetProp (event "ID");

			if (resource_id == event_id)
				{
					std::cout << "parada 1" << std::endl;
				}
			}
		}

You want to use

xmlStrEqual(resource_id, event_id)

it will return 1 if equal and 0 if different.

so

if(xmlStrEqual(resource_id, event_id))
       std::cout << "parada 1" << std::endl;

should do the trick.

http://xmlsoft.org/html/libxml-xmlstring.html#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.

As far as I know there is

int xmlStrEqual(const xmlChar * str1, 			 
                          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...

As far as I know there is

int xmlStrEqual(const xmlChar * str1, 			 
                          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 :)

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!

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/2003-April/msg00060.html

This article has been dead for over six months. Start a new discussion instead.