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. [Solved]QDomDocument

[Solved]QDomDocument

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 7.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.
  • M Offline
    M Offline
    Mr.FreakyJo
    wrote on 1 Jun 2012, 09:48 last edited by
    #1

    Hy...I use QDomDocument::setContent(QString) with a string long of over 1KK characters.The problem is the the QDomDocument retains only 78K characters.Is it because of a limit or it can be something else?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      derf_r
      wrote on 1 Jun 2012, 12:31 last edited by
      #2

      hello

      It's strange. I just tested with a xml file (351Ko).
      I read the file, use setContent, and save the file.

      Do you test if the return value of the function is true ?

      Do you test if your string containt a well formed xml document ?

      Best regards
      Frédéric

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mr.FreakyJo
        wrote on 1 Jun 2012, 15:07 last edited by
        #3

        The return value is false.This is the error message:
        "error occurred while parsing reference" .The document type is :
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> .What can I do to remediate the problem?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on 2 Jun 2012, 18:46 last edited by
          #4

          Just a blind guess: The document contains HTML character entities like &auml; or &frac14;. If you do not include the definition of these entities into your document or make it available to be loaded by the parser.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mr.FreakyJo
            wrote on 3 Jun 2012, 07:52 last edited by
            #5

            Some hints on how I can do that would be a huge help .Thank you for your help.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on 3 Jun 2012, 11:30 last edited by
              #6

              The first step is to determine what really causes the error:

              This snippet will show you the exact line and column with an error message where the parser bailed out:

              @
              #include <QtCore/QCoreApplication>
              #include <QFile>
              #include <QDomDocument>
              #include <QDebug>

              int main(int argc, char *argv[])
              {
              QCoreApplication a(argc, argv);

              QFile xmlFile&#40;"xhtml-test.xml"&#41;;
              xmlFile.open(QIODevice::ReadOnly);
              
              QString errorMessage;
              int errorLine, errorColumn;
              
              QDomDocument doc;
              bool xmlOk = doc.setContent(&xmlFile, &errorMessage, &errorLine, &errorColumn);
              xmlFile.close();
              
              if(xmlOk)
                  qDebug() << "Loading XML file ok";
              else
                  qDebug() << "XML Error at line" << errorLine << "column" << errorColumn << ":" << errorMessage;
              
              return 0;
              

              }
              @

              Another option would be to use a tool like xmllint, wich is part of the "libxml":http://xmlsoft.org/ package.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mr.FreakyJo
                wrote on 3 Jun 2012, 11:47 last edited by
                #7

                I 've done that but when I open the XHTML file with notepad++ that line is empty,what program should I use to open the XHTML file?The error is "error occurred while parsing reference" .

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Mr.FreakyJo
                  wrote on 3 Jun 2012, 11:49 last edited by
                  #8

                  @for(item in outputSummary){
                  //this is the line where the parser stops
                  if(outputSummary.hasOwnProperty(item)){

                  if(summary[item].coords.length){
                  
                   docSource += &quot;\t\t\t\tcoords[\&quot;&quot; + item + &quot;\&quot;] = \&quot;&quot; + summary[item].coords.join(&quot; &quot;) + &quot;\&quot;;\n&quot;;
                  
                  }
                  

                  }@

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mr.FreakyJo
                    wrote on 3 Jun 2012, 12:21 last edited by
                    #9

                    When I put setContent() with a QString containing the code I get the error at line 989 but when I put setContent() with a .txt file the erorr is at line 1557 column 64.Here is line 1556 and 1557:
                    @//line 1556:
                    <input type="hidden" value="ſtergerea grupei" id="group_title_delete"/>
                    //Line 1557:
                    <input type="hidden" value="/game.php" village=57564&screen=overview_villages&mode=combined&group=0&partial=1" id="start_edit_group_link"/>@

                    The value attribute in line 1556 should be: "Ștergerea grupei" .

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on 3 Jun 2012, 20:55 last edited by
                      #10

                      Some encoding issue, I would say. Parsing XML documents from a QString is suboptimal, at best. QString is always a Unicode UTF-16 representation of the enclosed data. The contents can be contradictory to the encoding claimed in the XML header.

                      If you construct your XML manually, like here, concatenating QStrings you may run into some validity issues sooner or later (escaping of < and the like comes into mind). I would recommend using the XML stream classes to create the XML. It takes care of proper encoding. You can stream into a QByteArray or a file and pass that to the DOM classes.

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        Mr.FreakyJo
                        wrote on 4 Jun 2012, 06:02 last edited by
                        #11

                        Thx...in the end I used regular expresions (QRegExp) to extract what I need.

                        1 Reply Last reply
                        0

                        10/11

                        3 Jun 2012, 20:55

                        • Login

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