Results 1 to 5 of 5

Thread: XML parsing problem using SAX2

  1. #1
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default XML parsing problem using SAX2

    I'm want to parse a xml file twice or more times.
    So I do it like this:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. w = new test();
    6. w->show();
    7.  
    8. QFile file("Resources/substations.xml");
    9. QXmlInputSource inputSource(&file);
    10.  
    11. QXmlSimpleReader reader1, reader2;
    12. Paser1 handler1;
    13. reader1.setContentHandler(&handler1);
    14. reader1.setErrorHandler(&handler1);
    15. reader1.parse(inputSource);
    16.  
    17. Paser2 handler2;
    18. handler2.num_Vol = handler1.num_Vol;
    19. handler2.num_Trans = handler1.num_Trans;
    20. handler2.num_Bay = handler1.num_Bay;
    21. reader2.setContentHandler(&handler2);
    22. reader2.setErrorHandler(&handler2);
    23. reader2.parse(inputSource);
    24.  
    25. a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    26. return a.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 

    the error info: Parser error at line 1, column 1: unexpected end of file.
    why? because the first time parsing reader1.parse(inputSource) seems OK, and that the 2 handler handle the same xml file.

    any help would be appreciated.
    Last edited by Shawn; 13th June 2007 at 08:04.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: XML parsing problem using SAX2

    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    Shawn (14th June 2007)

  4. #3
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: XML parsing problem using SAX2

    I called file.seek(0) and it's OK
    Any way, Thanks!

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: XML parsing problem using SAX2

    Quote Originally Posted by Shawn View Post
    I called file.seek(0) and it's OK
    I think QXmlInputSource::reset() would have done it "transparently" for you.
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    Shawn (14th June 2007)

  7. #5
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: XML parsing problem using SAX2

    hehe, Thank u very much~

Similar Threads

  1. Problem in XML parsing ";" (semicolon) char
    By the_bis in forum Qt Programming
    Replies: 7
    Last Post: 1st June 2007, 11:21
  2. problem in xml parsing
    By Shawn in forum Qt Programming
    Replies: 4
    Last Post: 28th May 2007, 12:11
  3. Replies: 16
    Last Post: 7th March 2006, 15:57

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.