Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Beginner Help

Anonymous
2010-12-15
2013-05-20

  • Anonymous
    2010-12-15

    Hey,
    I've been trying to get TinyXML to work in my project. Unfortunately I cannot get even a simple test app to run. Rather, it likes to crash any program I put it in. Please, could somebody tell me what is wrong with the simple program below?

    The XML file looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <config>
        <!--This is a config file-->
        <Input keys="WASD"/>
    </config>
    

    My C++ source looks like this:

    #include "tinyXML/tinyxml.cpp"
    #include "tinyXML/tinyxmlerror.cpp"
    #include "tinyXML/tinyxmlparser.cpp"
    #include "tinyXML/tinystr.cpp"
    #include <string>
    #include <windows.h>
    std::string readXML(const char* tag, const char* label,const char* fname="config.xml") {
        TiXmlDocument doc(fname);
        std::string answer;
        if(doc.LoadFile()) {
            TiXmlElement* root = doc.RootElement();
            TiXmlNode* node = root->FirstChild( tag );
            answer=node->ToElement()->Attribute( label );
        }
        return answer;
    }
    int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) {
        MessageBox(NULL,readXML("Input","Keys").c_str(),"Alert",MB_OK);
        return 0;
    }
    

    What I get is this:

    The application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.

    And then this:

    A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.

    I'm using the latest version of MinGW, and everything compiles+links without warning or error.

    Thanks everyone!

     

  • Anonymous
    2010-12-22

    TiXmlNode* node = root->FirstChild( tag );
    answer=node->ToElement()->Attribute( label );

    are those pointer variables instantiated and valid?

     
  • Preston
    Preston
    2010-12-30

    i know this might be a little obvious but did you try just loading a simple xml document using tinyxml and not involving the windows api? maybe something at the console like:

    #include "tinystr.cpp"
    #include "tinyxml.cpp"
    #include "tinyxmlerror.cpp"
    #include "tinyxmlparser.cpp"
    #include <iostream>
    using namespace std;
    int main()
    {
            TiXmlDocument doc("testfile.xml");
            
            if(!doc.LoadFile())
               return 1;
            doc.Print();
    }
    

    you shouldn't have any problems with this if your tinyxml files are correct.

     
  • ela
    ela
    2011-01-02

    Thanks a lot, that resolved my C source =))

     
  • ela
    ela
    2011-01-02

    Hello everyone !!
    I'm a beginner and I've just download tinyxml.
    How can I get one information between the tags in order to put it in my structure please ?
    thank you

     

  • Anonymous
    2011-01-02

    Hey all,

    Thanks for your suggestions. After playing around with it for ages I got the code below to work. It's very similar to the first one and I can't figure out why this one is better, but it is, so hopefully it will help somebody. I'm using the same code as above but with this replacement:

    std::string readXML(const char* tag, const char* label,const char* fname="config.xml") {
        TiXmlDocument doc(fname);
        doc.LoadFile();
        if(!doc.LoadFile()) return label;
        TiXmlElement* root = doc.RootElement();
        TiXmlNode* node = root->FirstChild( tag );
        return (std::string)node->ToElement()->Attribute( label );
    }