1

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

所以,当我自己运行 RapidXML 程序时,它会解析文件并做它应该做的一切。但是,当我运行观察程序并将 XML 文件放置在 watch 目录中时,它被检测到,它被重命名,它被移动,但是 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 文件?

4

1 回答 1

1

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

ifstream theFile("/home/root/xmlparser/config.xml");
于 2013-12-17T08:50:33.373 回答