XML parsing problem (error triggered by consumer)



  • Hello,

    I'm trying to parse XML data that I recieve over a bluetooth socket by passing the QByteArray to the XML handler.
    The process works and the full data is transmitted but parsing fails on line 2, column 6 of the XML file even though the XML is completely legal (checked with W3Schools validator).

    Here's the function that takes and parses the XML:
    @bool SaxHandler::readFile(const QByteArray &data)
    {

    QXmlInputSource source;
    source.setData(data);
    QXmlSimpleReader xmlReader;
    
    qDebug() << source.data();
    
    xmlReader.setContentHandler(this);
    xmlReader.setErrorHandler(this);
    
    return xmlReader.parse(source);
    

    }@

    Here's the console output, also showing the contents of the XML file (The error details come from the error handler):
    @"<?xml version="1.0"?>
    <data>
    <wind_direction>50</wind_direction>
    <wind_speed>0</wind_speed>
    <temperature>12</temperature>
    <humidity>95</humidity>
    <rain>89</rain>
    </data>"

    fatalError: "error triggered by consumer"
    lineNumber: 2
    columnNumber: 6@

    The error seems to be between the 'a' and the '>', but I see nothing wrong and the XML is legal.
    What could possibly be wrong?

    Thanks in advance!



  • Looks like the problem is in my content handler, if i comment it out the parsing succeeds.
    @//xmlReader.setContentHandler(this)@

    I guess it was stupid of me to leave implementing it for later, all i had there was a qDebug() which i omitted from the above posts output. I just wanted to test if everyting works before i continue working, time to implement the handler then :)

    Thanks anyway!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.