0

I am trying to read and xml file and parsing it using the below code can somebody suggest what mistake I am making.

It shows the error

Error: (E549) uncaught exception: ConfigException: expected <

void ParserCnfFile::read(void) {
    ifstream file(m_file.m_name.c_str(), ios::in | ios::binary | ios::ate);
    if (file.is_open()) {
        file.seekg(0, ios::end);
        int size = file.tellg();
        m_file.m_contents = new char[size];
        file.seekg(0, ios::beg);
        file.read(m_file.m_contents, size);
        file.close();
    } else {
        throw ConfigException("ConfigExpection: Could not open \"" +
                              m_file.m_name + "\"");
    }
}

void ParserCnfFile::parse(void) {
    xml_document<> doc; // character type defaults to char
    try {
        doc.parse<0>(m_file.m_contents);
        flags
    } catch (rapidxml::parse_error& e) {
        cout << m_file.m_contents << endl;
        throw ConfigException(string() + "ConfigExpection: " + e.what());
    }

    xml_node<>* rootNode = doc.first_node();
    xml_node<>* node = rootNode->first_node();
}

This is my xml file.

<?xml version="1.0"?>
    <GlobalSettings>
        <Simulation>
            <TimeResolution unit="ns"> 100 </TimeResolution>
            <Duration unit="s"> 600 </Duration>
        </Simulation>
    </GlobalSettings>
  • When you create the char array, it needs to be ```size + 1``` – Carl Apr 14 '15 at 17:23
  • Thanks!! Yeah I tried with that also but its only read the file till first 2 lines of xml file then it shows the mentioned error can't able to figure why it's not parsing complete file. – Dhruva Shrivastava Apr 15 '15 at 13:04
  • You need to isolate these two functions, because right now they're is no way to know if your problem is actually with Rapid XML – Carl Apr 15 '15 at 13:48
  • Thanks! Yeah I think so....I am trying to debug it by separating both the functions. Thanks for suggestion. – Dhruva Shrivastava Apr 17 '15 at 12:17

0 Answers0