简体   繁体   中英

RapidXML does not parse when called with script

I have a folder being watched with iNotify. When a file is created in the folder, the watcher takes the file, renames it (with mv), and then moves it to another folder. A RapidXML program is then called with a bash script and is suppose to parse the XML contents of the file. The iNotify program is also restarted after the RapidXML program script call.

So, when I run the RapidXML program by itself, it parses the file and does everything it should. BUT, when I run the watcher and a XML file is placed in the watch directory, it is detected, it gets renamed, it gets moved but the RapidXML program freezes or kicks out (not sure which one) at the

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

line.

Here is a section my code for the RapidXML program:

#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.

Anyone know why it does not want to parse the XML file when called with a script?

看来,如果要使用doc.parse <0>命令,则必须指定文件的完整路径名,因此在我的情况下:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM