c++ - 使用脚本调用时 RapidXML 不解析

标签 c++ bash inotify rapidxml

我有一个正在使用 iNotify 监视的文件夹。在文件夹中创建文件时,watcher 获取该文件,重命名它(使用 mv),然后将其移动到另一个文件夹。然后使用 bash 脚本调用 RapidXML 程序,并假设解析文件的 XML 内容。在调用 RapidXML 程序脚本后,iNotify 程序也会重新启动。

因此,当我单独运行 RapidXML 程序时,它会解析文件并执行它应该执行的所有操作。但是,当我运行观察器并将一个 XML 文件放置在观察目录中时,它被检测到,它被重命名,它被移动但是 RapidXML 程序卡住或踢出(不确定是哪个)在

doc.parse<0>(&buffer[0]);

行。

这是我的 RapidXML 程序代码的一部分:

#include "xmlparser.h"

using namespace std;
using namespace rapidxml;

int main(int argc, char * argv[])
{
    //variable declaration left out for space purposes


xml_document<> doc;
xml_node<> * root_node;

ifstream theFile("config.xml");
vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
buffer.push_back('\0');

doc.parse<0>(&buffer[0]);
// find the root node
root_node = doc.first_node("configuration");
// iterate over the deltas
xml_node<> * deltas_node = root_node->first_node("deltas");

svn = boost::lexical_cast<double>(deltas_node->first_attribute("svn")->value());
svd = boost::lexical_cast<double>(deltas_node->first_attribute("svd")->value());
    ... //other variable assignments

xml_node<> * report_node = deltas_node->next_sibling("report");

optime = boost::lexical_cast<int>(report_node->first_attribute("optime")->value());
opstatusa = boost::lexical_cast<int>(report_node->first_attribute("opstatusa")->value());
... // other variable assignments

xml_node<> * timing_node = report_node->next_sibling("timing");

timing = boost::lexical_cast<int>(timing_node->first_attribute("timing"));

... // then I do some SQL stuff with the mysql cpp connector.

有人知道为什么在使用脚本调用时不想解析 XML 文件吗?

最佳答案

似乎如果你想使用 doc.parse<0> 命令,你必须指定文件的完整路径名,所以在我的例子中:

ifstream theFile("/home/root/xmlparser/config.xml");

关于c++ - 使用脚本调用时 RapidXML 不解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20568672/

相关文章:

Bash- 将变量转换为人类可读的格式(KB、MB、GB)

email - 如果修改了文件夹,如何发送电子邮件警报

java - 在Java中检测远程文件

c++ - Eigen::matrixXd 到 Double 的转换

c++ - 使用 Boost.Preprocessor 来减少代码重复

c++ - UTF-8 和 TinyXML

python - 从子进程更改父 shell 的环境

c++ - 如何在 GCC 中启用反斜杠支持?

python - 使用 Python 2.7.3 的自动背景转换器不起作用,但它应该

linux - 在 go-inotify 中观察递归目录