How to write XML with POCO library in ROS environment

I want to create a C ++ program that reads and writes xml using the POCO library.

So, I am writing a simple program.

I could read every xml element.

But I could not write new xml elements.

The following is test.xml.

<config>
    <prop1>value1</prop1>
</config>

And this is my code.

#include <iostream>
#include <string>
#include <Poco/AutoPtr.h>
#include <Poco/Util/XMLConfiguration.h>

using Poco::AutoPtr;
using Poco::Util::XMLConfiguration;

int main(int argc, char const* argv[])
{
    AutoPtr<XMLConfiguration> pConf(new XMLConfiguration("test.xml"));

    std::string prop1 = pConf->getString("prop1");
    std::cout << "prop1 =  " << prop1 << std::endl;

    pConf->setString("prop2", "input");
    pConf->save("test.xml");

    return 0;
}

After running this program, I want the xml file to change as shown below.

<config>
    <prop1>value1</prop1>
    <prop2>input</prop2> <--New element added!!
</config>

But the result will be as shown below.

<config>
    <prop1>value1</prop1>
</config>

Nothing changed...

What am I doing wrong?

Thanks in advance.

Added info below

  • OS :: Linux Mint18.1
  • POCO Library Version :: 1.7.6 (Source Code Source)
  • Build System :: CMake and make and GCC

I run the following command.

sudo apt-get remove ros-kinetic-desktop-full

Then I could write an xml file using the above program.

I think ros uses the POCO library and duplicates my POCO library.

POCO (ros) POCO ().

!

+3
1

xml xml POCO.

POCO ROS POCO .

.

  • ROS

    sudo apt-get install ros-kinetic-desktop-full

  • Poco /usr/lib /usr/include

    ./configure - =/usr

    sudo make install

0

Source: https://habr.com/ru/post/1671274/


All Articles