Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: QDomDocument can't read the file content

  1. #1
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default QDomDocument can't read the file content

    Hi,

    In my Qt mobile application I am trying to read the xml file with QDomDocument, but QDom is not bale to read the content from the file even the file was existed and has some data.

    Qt Code:
    1. file = new QFile("file.xml");
    2. if(!file->open(QIODevice::ReadWrite | QIODevice::Text))
    3. {
    4. exit(1);
    5. }
    6. if(!doc.setContent(file))
    7. {
    8. exit(1);
    9. } else
    10. {
    11. ......
    12. }
    To copy to clipboard, switch view to plain text mode 

    After the if(!doc.setContent(file)) statement the program simply exited with status code 1. I would be grateful for any help.

    Thank you,
    Baluk

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QDomDocument can't read the file content

    Then it is probably not well formed. Use all parameters of setContent and see what error message you get.

  3. #3
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomDocument can't read the file content

    yes, I have now used all the parameters and am getting the error ""unexpected end of file" at line: 2 col: 1 ". But my xml file format is correct with no sysntax errors.

    Thank you,
    Baluk

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QDomDocument can't read the file content

    Can you past the first 5 lines of your xml file.

  5. #5
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomDocument can't read the file content

    Here is the xml data. this format is working fine when I tried in other application in Windows. Now I am making mobile application in Linux environment.
    <?xml version="1.0" encoding="UTF-8"?>

    <list>

    <expenses>

    <name>city</name>

    <date>21/09/2010</date>
    <price>4000</price>

    </expenses>
    </list>
    Thank you,

    Baluk

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QDomDocument can't read the file content

    The only thing I can think of right know is, that it may be a problem with the encoding of your line breaks. Try to convert them to simple "\n" and try again of your device. (or remove all "\n" and "\r" for testing if that is the error.)

  7. #7
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomDocument can't read the file content

    I am sorry but what do you mean by removing "\n" and "\r" from the file. I have tried placing the data in one line without any breaks but still not working.

    Thank you,
    Baluk

  8. #8
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDomDocument can't read the file content

    what does file->readAll() return?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDomDocument can't read the file content

    Are you sure you are using the correct file? The error suggests your file has only one line.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomDocument can't read the file content

    nothing returned to the byte array.

    I have used this code
    Qt Code:
    1. file = new QFile("file.xml");
    2. QByteArray array;
    3. array = file->readAll();
    4. if(array.isNull())
    5. {
    6. qDebug() << "error" ;
    7. exit(1);
    8. }
    To copy to clipboard, switch view to plain text mode 

    program existed after the if statement.

  11. #11
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomDocument can't read the file content

    Yes it has data. I am checking it every time I runthrough the program.

    Thank you,

    Baluk

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDomDocument can't read the file content

    You have to open the file before reading it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDomDocument can't read the file content

    Quote Originally Posted by baluk View Post
    I am checking it every time I runthrough the program.
    How are you doing that?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomDocument can't read the file content

    Ya I did that , but getting the same result.

    Qt Code:
    1. QByteArray array;
    2. file = new QFile("expenses.xml");
    3.  
    4. if(!file->open(QIODevice::ReadWrite | QIODevice::Text))
    5. {
    6. exit(1);
    7. }
    8.  
    9.  
    10. array = file->readAll();
    11. if(array.isNull())
    12. {
    13. qDebug() << "error" ;
    14. exit(1);
    15. }
    To copy to clipboard, switch view to plain text mode 

    Thank you,
    Baluk

  15. #15
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomDocument can't read the file content

    I am just checking the file if the file data is erased after I execute the program by some means.
    Thank you,
    Baluk

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDomDocument can't read the file content

    Please run the following code with your file:
    Qt Code:
    1. #include <QtXml>
    2. #include <QtCore>
    3.  
    4. int main(int argc, char **argv){
    5. if(argc<2) return 1;
    6. QFile file(argv[1]);
    7. qDebug() << "File path:" << QFileInfo(file).absoluteFilePath();
    8. qDebug() << "File exists:" << file.exists();
    9. file.open(QFile::ReadOnly|QFile::Text);
    10. qDebug() << "File open:" << file.isOpen();
    11. QString error;
    12. int line, int column;
    13. if(dom.setContent(&file, &error, &line, &column)){
    14. qDebug() << dom.toString(4);
    15. } else {
    16. qDebug() << "Error:" << error << "in line " << line << "column" << column;
    17. }
    18. return 0;
    19. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDomDocument can't read the file content

    can you attach your xml file here? if not confidential of course.

  18. #18
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomDocument can't read the file content

    I run the code but and I get the error "../newxml-build-desktop/newxml exited with code 1".

    Thank You,
    Baluk.

  19. #19
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDomDocument can't read the file content

    Hi,

    Ya sure, I am still in the beginning so no issue. Here is the file

    Thank you,
    Baluk
    Attached Files Attached Files

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDomDocument can't read the file content

    Quote Originally Posted by baluk View Post
    I run the code but and I get the error "../newxml-build-desktop/newxml exited with code 1".
    Did you pass it the path to your file?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  21. The following user says thank you to wysota for this useful post:

    baluk (24th September 2010)

Similar Threads

  1. Read SMS in-box content & show it in QListWidget?
    By damodharan in forum Qt Programming
    Replies: 3
    Last Post: 4th June 2010, 06:51
  2. set content(&file)
    By rk0747 in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2010, 09:31
  3. read and write content of lineedit widget in Other Form
    By validator in forum Qt Programming
    Replies: 1
    Last Post: 25th April 2008, 16:07
  4. Replies: 13
    Last Post: 10th October 2007, 16:38
  5. QDomDocument Speed by 24MB file
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 30th April 2007, 22:35

Tags for this Thread

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.