如何在ROS环境中使用POCO库编写XML

How can write XML with POCO library in ROS environment

本文关键字:POCO XML ROS 环境      更新时间:2023-10-16

我想创建C 程序,该程序使用POCO库读写XML。

所以,我写了简单的程序。

我可以阅读每个XML元素。

,但我无法编写新的XML元素。

下面是test.xml。

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

这是我的代码。

#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;
}

运行此程序后,我希望XML文件如下。

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

,但结果如下。

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

什么都没有改变...

我在做什么错?

预先感谢。

添加了如下

的信息
  • OS :: Linux Mint18.1
  • Poco Library版本:: 1.7.6(从源代码构建)
  • 构建系统:: cmake and Make and gcc

我运行以下命令。

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

然后,我可以使用上述程序编写XML文件。

我认为ROS使用Poco库,它重复了我的Poco库。

所以我尝试将Poco Library(ROS)替换为Poco Library(Mine)。

我的尝试很好!


解决方案如下

如果您可以读取XML文件并且不能使用POCO库编写XML文件。

您的Poco库和ROS的Poco库可能会重复。

尝试以下命令。

  1. 安装ros

    sudo apt-get安装ros-kinetic-desktop-full

  2. 重新安装Poco库>目标前缀 to/usr/lib和/usr/include

    ./configure - prefix =/usr

    make

    sudo make install