Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Issue with QDomDocument::setContent and XML declaration attribute quotes

Issue with QDomDocument::setContent and XML declaration attribute quotes

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.1k Views
  • 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 Offline
    E Offline
    evanol
    wrote on last edited by evanol
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved