Hi,
I am reading off a streaming socket. Which is to say, I can send commands to the server, but it generally constantly streams data in XML format.
The xml that is streamed isn't very well formatted. There's not much I can do about that. But, it tends to have this format:
<CinQoConnected id='1365p' />
<HardwareRevision id='1365p' timestamp='1256437880.14' version='10' />
<Manufacturer id='1365p' timestamp='1256437880.14' mfg_id='7' />
<ModelNumber id='1365p' timestamp='1256437880.14' model_id='1' />
<Power id='1365p' timestamp='1256437880.63' watts='0.00' />
<Torque id='1365p' timestamp='1256437880.63' Nm='0.00' />
<Cadence id='1365p' timestamp='1256437880.63' RPM='3.09' />
<Power id='1365p' timestamp='1256437910.59' watts='0.00' />
<Torque id='1365p' timestamp='1256437910.59' Nm='0.00' />
<Cadence id='1365p' timestamp='1256437910.59' RPM='8.39' />
<CinQoConnected id='1365p' />
<HardwareRevision id='1365p' timestamp='1256437917.34' version='10' />
<Manufacturer id='1365p' timestamp='1256437917.34' mfg_id='7' />
<ModelNumber id='1365p' timestamp='1256437917.34' model_id='1' />
<RawTorque id='1365p' timestamp='1256437921.09' Nm='-1' />
<OffsetTorque id='1365p' timestamp='1256437921.09' Nm='-98' />
<SensorConfiguration id='1365p' timestamp='1256437921.09' config='3' />
<BatteryVoltage id='1365p' timestamp='1256437921.58' voltage='2.96' />
<CinQoConnected id='1365p' />
<CinQoConnected id='1365p' />
<HardwareRevision id='1365p' timestamp='1256437880.14' version='10' />
<Manufacturer id='1365p' timestamp='1256437880.14' mfg_id='7' />
<ModelNumber id='1365p' timestamp='1256437880.14' model_id='1' />
<Power id='1365p' timestamp='1256437880.63' watts='0.00' />
<Torque id='1365p' timestamp='1256437880.63' Nm='0.00' />
<Cadence id='1365p' timestamp='1256437880.63' RPM='3.09' />
<Power id='1365p' timestamp='1256437910.59' watts='0.00' />
<Torque id='1365p' timestamp='1256437910.59' Nm='0.00' />
<Cadence id='1365p' timestamp='1256437910.59' RPM='8.39' />
<CinQoConnected id='1365p' />
<HardwareRevision id='1365p' timestamp='1256437917.34' version='10' />
<Manufacturer id='1365p' timestamp='1256437917.34' mfg_id='7' />
<ModelNumber id='1365p' timestamp='1256437917.34' model_id='1' />
<RawTorque id='1365p' timestamp='1256437921.09' Nm='-1' />
<OffsetTorque id='1365p' timestamp='1256437921.09' Nm='-98' />
<SensorConfiguration id='1365p' timestamp='1256437921.09' config='3' />
<BatteryVoltage id='1365p' timestamp='1256437921.58' voltage='2.96' />
<CinQoConnected id='1365p' />
To copy to clipboard, switch view to plain text mode
This is the code I am using..
void QuarqdClient::readyForRead()
{
QXmlStreamReader xml(tcpSocket);
while(!xml.atEnd())
{
QXmlStreamReader::TokenType token = xml.readNext();
qDebug() << "Token is: " << token;
qDebug() << xml.name();
if(token == QXmlStreamReader::StartElement)
{
if(xml.name() == "Power")
{
QXmlStreamAttributes attrib = xml.attributes();
QStringRef watts = attrib.value("watts");
qDebug() << "Watts: " << watts;
}
else if(xml.name() == "Cadence")
{
QXmlStreamAttributes attrib = xml.attributes();
QStringRef rpm = attrib.value("RPM");
qDebug() << "Cadence: " << rpm;
}
}
}
if(xml.hasError()) {
qDebug() << xml.errorString();
}
xml.clear();
}
void QuarqdClient::readyForRead()
{
QXmlStreamReader xml(tcpSocket);
while(!xml.atEnd())
{
QXmlStreamReader::TokenType token = xml.readNext();
qDebug() << "Token is: " << token;
qDebug() << xml.name();
if(token == QXmlStreamReader::StartElement)
{
if(xml.name() == "Power")
{
QXmlStreamAttributes attrib = xml.attributes();
QStringRef watts = attrib.value("watts");
qDebug() << "Watts: " << watts;
}
else if(xml.name() == "Cadence")
{
QXmlStreamAttributes attrib = xml.attributes();
QStringRef rpm = attrib.value("RPM");
qDebug() << "Cadence: " << rpm;
}
}
}
if(xml.hasError()) {
qDebug() << xml.errorString();
}
xml.clear();
}
To copy to clipboard, switch view to plain text mode
The problem is I am getting lots of xml errors. Unexpected end of document, Extra data in document.. etc, etc.
Not only that but I can't see to ever hit the cadence name.. I suspect it's hitting an error before..
Is this a good candidate for XmlStreamReader or am I better off reading the data and parsing it myself by hand ?
Oh and the stream of tokens looks like this:
Token is: 5
Token is: 1
Token is: 2
Token is: 4
Token is: 5
Token is: 3
Token is: 2
Token is: 4
Token is: 5
Token is: 3
Token is: 2
Token is: 4
Token is: 5
Token is: 3
Token is: 2
Token is: 4
Token is: 5
Token is: 1
Token is: 2
Token is: 4
Token is: 5
Token is: 3
Token is: 5
Token is: 1
Token is: 2
Token is: 4
Token is: 5
Token is: 3
Token is: 2
Token is: 4
Token is: 5
Token is: 3
Token is: 2
Token is: 4
Token is: 5
Token is: 3
Token is: 2
Token is: 4
Token is: 5
Token is: 1
Token is: 2
Token is: 4
Token is: 5
Token is: 3
To copy to clipboard, switch view to plain text mode
Thanks
J
Bookmarks