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
QtWS25 Last Chance

Dom document set content error

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.0k 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.
  • P Offline
    P Offline
    Paytam
    wrote on 5 Jan 2014, 18:12 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 5 Jan 2014, 18:18 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 6 Jan 2014, 05:21 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
        • D Offline
          D Offline
          dheerendra
          Qt Champions 2022
          wrote on 6 Jan 2014, 06:37 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
          • I Offline
            I Offline
            IamSumit
            wrote on 6 Jan 2014, 06:49 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

            1/5

            5 Jan 2014, 18:12

            • Login

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