Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Unsolved Issue with QDomDocument::setContent and XML declaration attribute quotes

    General and Desktop
    2
    2
    959
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      evanol last edited by evanol

      Hello
      I'm having an issue when importing an XML document from a string.

      The XML declaration/preprocessor has two attributes (version, encoding) which are defined within double-quotes.
      However, on creating a QDomDocument via the setContent method, the double-quotes are replaced with single-quotes but only for the declaration/preprocessor element, the root element attributes still use double-quotes.

      QDomDocument::toString() :

      packet : 
      "<?xml version="1.0" encoding="UTF-8"?>
      <pkt uniqueID="fe87d654-dded-44e6-8c6a-70c92ebd4d7d" version="1">
       <inner uniqueID="dca0ddd7-2e91-492f-b61c-d4962a003dd9">
        <element>value</element>
       </inner>
      </pkt>"
      

      QDomDocument::SetContent(...) ... toString() :

      getPacket : 
      "<?xml version='1.0' encoding='UTF-8'?>
      <pkt uniqueID="fe87d654-dded-44e6-8c6a-70c92ebd4d7d" version="1">
       <inner uniqueID="dca0ddd7-2e91-492f-b61c-d4962a003dd9">
        <element>value</element>
       </inner>
      </pkt>"
      

      The data is being used in a transmission protocol where on the receiving end it needs to be verified via a checksum - this verification will fail due to the conversion from double-quotes to single-quotes.

      Any ideas on how I can preserve the use of double-quotes across conversion?

      Thanks

      See code below used to recreate the issue:

      int main( void )
      {
          QDomDocument packet = pDoc.document();
          QString stringPacket = packet.toString();
          qDebug() << "packet :" << endl << stringPacket;
      
          QString errorMessage; int errorLine; int errorColumn;
          QDomDocument getPacket;
          if( !(getPacket.setContent( stringPacket, &errorMessage, &errorLine, &errorColumn)) )
          {
              qDebug() << "!! error !!" << endl
                       << "message :" << errorMessage << endl
                       << "errorLine :" << errorLine << endl
                       << "errorColumn :" << errorColumn;
          }
          qDebug() << "getPacket :" << endl << getPacket.toString();
      }
      
      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        I think that the most quickly implemented solution would be to use QString's replace function and update the first line appropriately.

        Hope it helps.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • First post
          Last post