2

I am using TinyXML2 and I got some strange problem. So It seems it work because I dont have any crashes but when I want to output one of the value I got I have nothing , if someone know why ? I already used tinyxml2 and it was working but here maybe the XML is strange?

#include <iostream>
#include "tinyxml2/tinyxml2.cpp"
#include "../Inc/classConfigCtx.h"
#include "../Inc/globalDefine.h"


using namespace tinyxml2;
int main() {
    std::cout << "Hello World!";
    XMLDocument doc;
    doc.LoadFile( "NetworkConfig.xml" );
    int AppliMsgPort_;
    const char * portAppli;
    const char * IPtemp;

    XMLElement * pRootElement =doc.RootElement()->FirstChildElement();
    portAppli=pRootElement->FirstChildElement()->GetText();

    std::cout<<portAppli;

    return 0;
}

and my XML

<configuration>

<operational_00001000><name value="100.CBD" /><radio_1><type value="Net" /><ip value="10.36.1.1" /><port_s value="50010" /><port_r value="50100" /><radioID value="10040" /></radio_1></operational_00001000>

<operational_00001005><name value="100.LOG" /><radio_1><type value="Net" /><ip value="10.26.2.1" /><port_s value="50000" /><port_r value="50000" /><radioID value="1000005" /></radio_1></operational_00001005>
</configuration>
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
aetopiu
  • 41
  • 2
  • That code is working correctly - there is no text in your sample XML file! What exactly are you trying to access? – Ken Y-N May 11 '21 at 06:23
  • Hello @KenY-N thanks for your answer , I would like to get port_s and ip of both line :) But my code is working but my cout not showing anything when I run this code I only get hello word – aetopiu May 11 '21 at 06:26
  • 1
    THen you need the [`Atrribute("value")`](https://leethomason.github.io/tinyxml2/classtinyxml2_1_1_x_m_l_element.html#a70e49ed60b11212ae35f7e354cfe1de9) API. – Ken Y-N May 11 '21 at 06:30
  • YEAH you'r a killer thanks @KenY-N , How do I close the topic? – aetopiu May 11 '21 at 06:37
  • Don't close it - it may help someone else later; just leave as is. – Ken Y-N May 11 '21 at 09:20
  • 1
    @KenY-N Why don't you flesh your comment out as an actual answer? This will make it clearer that a solution was found. – Andrew Truckle Jun 11 '21 at 07:58

0 Answers0