Results 1 to 10 of 10

Thread: Why Qxmlstreamreader returns pair of quotes and double empty lines beetween elements

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Why Qxmlstreamreader returns pair of quotes and double empty lines beetween elements

    I have such xml-file contents written with Qxmlstreamwriter:
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8" ?>
    2. - <FILESYSTEM>
    3. - <FILE>
    4. <NAME>autoc.JPG</NAME>
    5. <SIZE>19197</SIZE>
    6. <PATH>c:/c</PATH>
    7. </FILE>
    8. - <FILE>
    9. <NAME>copy autoc.JPG</NAME>
    10. <SIZE>19197</SIZE>
    11. <PATH>c:/c</PATH>
    12. </FILE>
    13. - <FILE>
    14. <NAME>copy copy autoc.JPG</NAME>
    15. <SIZE>19197</SIZE>
    16. <PATH>c:/c</PATH>
    17. </FILE>
    18. - <FILE>
    19. <NAME>copy copy copy autoc.JPG</NAME>
    20. <SIZE>19197</SIZE>
    21. <PATH>c:/c</PATH>
    22. </FILE>
    23. </FILESYSTEM>
    To copy to clipboard, switch view to plain text mode 
    I try to extract the same view and order of this xml to console (but then in GUI TextEdit) with such
    simple function:
    Qt Code:
    1. void Mainclas::readxmlfile()
    2. {
    3. QXmlStreamReader Rxml;
    4. QString filename="D:\\file00.xml";
    5. QFile file(filename);
    6. file.open(QIODevice::ReadOnly);
    7. Rxml.setDevice(&file);
    8. Rxml.readNext();
    9. while(!Rxml.atEnd())
    10. {
    11. if(Rxml.isStartDocument()) {
    12. qDebug()<<"<?xml"<<Rxml.documentEncoding ().toString()<<" "<<Rxml.documentVersion().toString()<<"?>";
    13. Rxml.readNext();
    14. }
    15. if(Rxml.isStartElement()) {
    16. qDebug()<<"<"+Rxml.name().toString()<<">";
    17. Rxml.readNext();
    18. }
    19. if(Rxml.isEndElement()) {
    20. qDebug()<<"</"+Rxml.name().toString()<<">";
    21. Rxml.readNext();
    22. }
    23. if(Rxml.isCharacters ()) {
    24. if(Rxml.text()=="") Rxml.readNext();
    25. qDebug()<<Rxml.text();
    26. Rxml.readNext();
    27. }
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 
    But I got
    Qt Code:
    1. "<FILESYSTEM" >
    2. "
    3. "
    4. <FILE>
    To copy to clipboard, switch view to plain text mode 
    Here is console printscreen - readxml.jpg
    Why it happened? how to resolve it?
    Should it be some error due to absent of such eroor-handler?
    Last edited by artt; 8th December 2015 at 22:08.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Why Qxmlstreamreader returns pair of quotes and double empty lines beetween eleme

    You are probably missing a readNext() call.
    Better put it at the beginning or the end of the loop.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Why Qxmlstreamreader returns pair of quotes and double empty lines beetween eleme

    There are several readNext() 's- where I should put next one?
    Here is similar question but also without answer -
    http://www.qtcentre.org/threads/6454...ments?p=285154

  4. #4
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Why Qxmlstreamreader returns pair of quotes and double empty lines beetween eleme

    What would you do better in this situation (to extract the xml identically), if have not any suggestion concerning quotes?

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Why Qxmlstreamreader returns pair of quotes and double empty lines beetween eleme

    The example you post is not well formed XML. I would be surprised if it was written by QXmlStreamWriter.

    In all likelihood, the output at lines 2 and 3 is put there by line 25 of your code. QDebug added the quotes and between the quotes are the end of line character and leading spaces from two consecutive lines in the input file. QDebug is a debugging tool not a general purpose output generating tool. The quotes are useful to help tell the difference between an empty string "" and one containing only whitespace characters " ".

    If you want a general purpose text output stream then look at QTextStream.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Why Qxmlstreamreader returns pair of quotes and double empty lines beetween eleme

    Quote Originally Posted by artt View Post
    There are several readNext() 's- where I should put next one?
    The readNext() statements are all in weird places.
    There should be only one at either the beginning or end that advances the stream.

    Cheers,
    _

  7. #7
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Why Qxmlstreamreader returns pair of quotes and double empty lines beetween eleme

    Really, in case of just one readnext() - in the beginning or the end of while loop we can have xml display -but the same in every detail - so my approach is correct and it doesnt influence the quotes - can I directly ask this question in trolltech team?

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Why Qxmlstreamreader returns pair of quotes and double empty lines beetween eleme

    You have already been told where the quotes came from and it has nothing to do with the QXmlStreamReader.

    Trolltech has not existed since circa 2008when it became part of Nokia and later the Qt Company

Similar Threads

  1. Replies: 7
    Last Post: 21st March 2014, 10:24
  2. Replies: 2
    Last Post: 5th December 2013, 06:35
  3. Replies: 1
    Last Post: 30th November 2013, 11:03
  4. Replies: 9
    Last Post: 22nd February 2013, 12:27
  5. Replies: 3
    Last Post: 27th December 2009, 00:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.