| | |
Convert xmlChar to int
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 11
Reputation:
Solved Threads: 0
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:
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)
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
it will return 1 if equal and 0 if different.
so
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.
C++ Syntax (Toggle Plain Text)
xmlStrEqual(resource_id, event_id)
it will return 1 if equal and 0 if different.
so
C++ Syntax (Toggle Plain Text)
if(xmlStrEqual(resource_id, event_id)) 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.
As far as I know there is
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...
c Syntax (Toggle Plain Text)
int xmlStrEqual(const xmlChar * str1, const xmlChar * str2)
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
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...c Syntax (Toggle Plain Text)
int xmlStrEqual(const xmlChar * str1, const xmlChar * str2)
I don't use libxml now then can't present ready-to-use code. Look at libxml2 manual...
Last edited by Paul.Esson; Nov 22nd, 2008 at 8:28 pm.
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
Post I found is http://mail.gnome.org/archives/xml/2.../msg00060.html
![]() |
Other Threads in the C++ Forum
- Previous Thread: g++ error?
- Next Thread: Simple circular bit shifts, in C++
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






