Hello everybody, ive been looking for an answer to this basic (i thing) issue:
Im making a class to read a XML file but the compiling errors are driving me crazy, i cannot figure out how to solve this problem, so here is the code if anyone can help me:

-------------------------
#include <iostream>
using namespace std;
#include "leeXML.h"

int main (int argc, char* argv[])
{
    xmlDocPtr doc;
    doc = xmlParseFile(argv[1]);
    doc.leerEntrada();
        return 0;
}
-------------------------

When i compile the class it gives me this error:

-------------------------    
main.cc: In function ‘int main(int, char**)’:
main.cc:9: error: request for member ‘leerEntrada’ in ‘doc’, which is of non-class type ‘xmlDoc*’
-------------------------

So i found on google the right way to write the code is changing the . for -> on the line doc.leerEntrada();. Then when i try that way it gives me this another error:

-------------------------
main.cc: In function ‘int main(int, char**)’:
main.cc:9: error: ‘struct _xmlDoc’ has no member named ‘leerEntrada’
-------------------------

What means those errors?
Plase help, it is very important!!

can you try doing this

int main (int argc, char& argv[])

no, it gives me a bouch of errors, i think the problem is in the line of:
doc.leerEntrada();
if i comment that line the class compiles normally, of course does not do nothing, so i need to know how to hanlde that information to pass "doc" to "leerEntrada", thats what i need because if write the same procedure in mail after doc.leerEntrada(); it gives me no errors and the program work.

This is the reason I think making typedefs to pointers is a bad idea...

It looks like you did the right thing, but the compiler is saying that the xmlDoc class does not publish a method named leerEntrada(). It looks like you are including the correct files (since the compiler can complain about the struct _xmlDoc), so you should look in the "leeXML.h" file and check that it really does have something like the following in it.

typedef struct _xmlDoc
  {
  ...
  public:
    void leerEntrada();
    ...
  };

Is it possible that you have mis-capitalized the name of the function? LeerEntrada() Or perhaps the function is named something else? You can look through the header file to see if there is anything named to suggest reading the XML header (I presume by "entrada" it means the XML header.)

Hope this helps.

Oh, yeah, please post your code in code tags:
[[B][/B]code[B][/B]]
Code goes here
[[B][/B]/code[B][/B]]


[edit] Is the library publicly available? If it is I'll see if I can find it.

The type xmlDocPtr implies that it's a typedef for a pointer. Edward really doesn't like this practice since it causes exactly this problem: not using the right membership operator. Ed's guess is that instead of this:

doc.leerEntrada();

You should use this:

doc->leerEntrada();

p.s. Nevermind. Ed didn't read all of the post and missed that you already tried that. Make sure that you're spelling leerEntrada correctly, and remember that case counts! :)

what are you trying to do with doc.leerEntrada()?? the "." operator is used for members of a struct..is leerEntrada a function??well it seems am not getting the whole problem clearly..i think you should post your struct definition

[EDIT] oops too late with my post :)
[another EDIT] just realised these are classes...oops..

No offense, but he already addressed that in his first post. ;) Wake up! heh heh heh

/me runs off to eat

[edit] man, too slow again... :S

Well this is the code, i compile it with
# g++ -o leeXML leeXML.cc main.cc -lxml2
leeXML.h

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <iostream>

class LeeXML
{
public:
xmlChar *txt;
xmlDocPtr doc;
xmlNodePtr cur, sub, node, ava, fea, res, eve, cons;

void leerEntrada(xmlDoc*);
private:
};

leeXML.cc

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <iostream>

using namespace std;
#include "leeXML.h"

void LeeXML::leerEntrada(xmlDoc* doc)
{
doc = xmlParseFile(doc);
node = xmlDocGetRootElement(doc);
std::cout << " -----------------------" << std::endl;
printf("You are in: %s\n", node->name);

main.cc

#include <iostream>
using namespace std;
#include "leeXML.h"

int main (int argc, char* argv[])
{
xmlDocPtr doc;
doc = xmlParseFile(argv[1]);
doc->leerEntrada();
return 0;
}

The error message is:
main.cc: In function ‘int main(int, char**)’:
main.cc:13: error: ‘struct _xmlNode’ has no member named ‘leerEntrada’

Ah, you are mixing classes.

The class LeeXML has a member function named leerEntrada(), but xmlDoc does not.

You need to create a reader object first, then use it to read the document object.

xmlDocPtr doc = xmlParseFile(argv[1]);
LeeXML leador;
leador.leerEntrada( doc );

Hope this helps.

Men, that was the problem! thanks to you and everybody who posted here, it was the first question not the last one so i'll be here for a while. Hope help you in the future!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.