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. Dom document set content error

Dom document set content error

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.1k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Paytam
    wrote on last edited by
    #1

    Hi
    I want to use xml with dom approach with QT. the first line of xml file is this
    <?xml version="1.0" encoding="utf-16">
    this line automatically generated with dom document
    but the problem arises when I want to read the content. when I use setContent method it breaks. on this line and first column. if I remove this line everything is fine. what's should i do?
    Qt version 5.2
    OS:windows 7 x64
    compiler :VS2012

    1 Reply Last reply
    0
    • M Offline
      M Offline
      martonmiklos
      wrote on last edited by
      #2

      Could you please post a code snipplet and a sample XML file?

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Paytam
        wrote on last edited by
        #3

        <?xml version=“1.0” encoding=“UTF-16”>
        <Tables>
        <Table Version="1.0" CreateDate="2014/01/01" isDelete="false" ModifiedDate="">
        <me>1</me>
        <you>2</you>
        </Table>
        <Table Version="1.0" CreateDate="2014/01/01" isDelete="false" ModifiedDate="">
        <me>1</me>
        <you>2</you>
        </Table>
        </Tables>

        @QDomDocument document;
        QFile xmlFile(QString::fromUtf16(tablePath));
        QByteArray xml;
        xml=xmlFile.readAll();
        xmlFile.close();
        QString errorMsg ;
        int errorLine , errorColumn ;
        if(!document.setContent(xml,&errorMsg,&errorLine,&errorColumn)){
        if(errorMsg!="unexpected end of file"){
        result=-1;
        return result;
        }
        }
        QDomNode root= document.namedItem(rootName);
        QDomNodeList nodeList=document.elementsByTagName(rootName);
        //the rest of code@

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          What is the error you are observing ?

          Can you try something like this ?

          @ QFile file(fileName);
          if (!file.open(QFile::ReadOnly | QFile::Text)) {
          qDebug() << "Error " << endl;
          return false;
          }

          QString err;
          int errL, errC;
          
          QDomDocument doc;
          if (!doc.setContent(&file, false, &err, &errL, &errC))@
          

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • IamSumitI Offline
            IamSumitI Offline
            IamSumit
            wrote on last edited by
            #5

            Hello Paytam,

            The xml that u have posted on forum is invalid.
            because i can't see an ending tag of
            Table..where is that ???

            Be Cute

            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