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:

Qt Code:
  1. <CinQoConnected id='1365p' />
  2. <HardwareRevision id='1365p' timestamp='1256437880.14' version='10' />
  3. <Manufacturer id='1365p' timestamp='1256437880.14' mfg_id='7' />
  4. <ModelNumber id='1365p' timestamp='1256437880.14' model_id='1' />
  5. <Power id='1365p' timestamp='1256437880.63' watts='0.00' />
  6. <Torque id='1365p' timestamp='1256437880.63' Nm='0.00' />
  7. <Cadence id='1365p' timestamp='1256437880.63' RPM='3.09' />
  8. <Power id='1365p' timestamp='1256437910.59' watts='0.00' />
  9. <Torque id='1365p' timestamp='1256437910.59' Nm='0.00' />
  10. <Cadence id='1365p' timestamp='1256437910.59' RPM='8.39' />
  11. <CinQoConnected id='1365p' />
  12. <HardwareRevision id='1365p' timestamp='1256437917.34' version='10' />
  13. <Manufacturer id='1365p' timestamp='1256437917.34' mfg_id='7' />
  14. <ModelNumber id='1365p' timestamp='1256437917.34' model_id='1' />
  15. <RawTorque id='1365p' timestamp='1256437921.09' Nm='-1' />
  16. <OffsetTorque id='1365p' timestamp='1256437921.09' Nm='-98' />
  17. <SensorConfiguration id='1365p' timestamp='1256437921.09' config='3' />
  18. <BatteryVoltage id='1365p' timestamp='1256437921.58' voltage='2.96' />
  19. <CinQoConnected id='1365p' />
To copy to clipboard, switch view to plain text mode 

This is the code I am using..

Qt Code:
  1. void QuarqdClient::readyForRead()
  2. {
  3.  
  4. QXmlStreamReader xml(tcpSocket);
  5. while(!xml.atEnd())
  6. {
  7. QXmlStreamReader::TokenType token = xml.readNext();
  8. qDebug() << "Token is: " << token;
  9. qDebug() << xml.name();
  10. if(token == QXmlStreamReader::StartElement)
  11. {
  12. if(xml.name() == "Power")
  13. {
  14. QXmlStreamAttributes attrib = xml.attributes();
  15. QStringRef watts = attrib.value("watts");
  16. qDebug() << "Watts: " << watts;
  17. }
  18. else if(xml.name() == "Cadence")
  19. {
  20. QXmlStreamAttributes attrib = xml.attributes();
  21. QStringRef rpm = attrib.value("RPM");
  22. qDebug() << "Cadence: " << rpm;
  23. }
  24. }
  25. }
  26. if(xml.hasError()) {
  27. qDebug() << xml.errorString();
  28. }
  29. xml.clear();
  30. }
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:

Qt Code:
  1. Token is: 5
  2. Token is: 1
  3. Token is: 2
  4. Token is: 4
  5. Token is: 5
  6. Token is: 3
  7. Token is: 2
  8. Token is: 4
  9. Token is: 5
  10. Token is: 3
  11. Token is: 2
  12. Token is: 4
  13. Token is: 5
  14. Token is: 3
  15. Token is: 2
  16. Token is: 4
  17. Token is: 5
  18. Token is: 1
  19. Token is: 2
  20. Token is: 4
  21. Token is: 5
  22. Token is: 3
To copy to clipboard, switch view to plain text mode 

Thanks

J