Question

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?

Was it helpful?

Solution

It seems if you want to use the doc.parse<0> command, you have to specify the full pathname for the file, so in my case:

ifstream theFile("/home/root/xmlparser/config.xml");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top