Results 1 to 5 of 5

Thread: Xml parsing

  1. #1
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Xml parsing

    I want to parse a very simple QString, which contains text in XML format

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <data>
    <method>loginRequest</method>
    <userName>user</userName>
    <userPassword>password</userPassword>
    </data>

    So far I am able to verify that this XML is well formed.

    Now, I would like to get the information inside each tag. For example: I would like to get "user", which is inside the <userName> tag.

    From the documentation I have understood that the class and funtion should return the value of whatever is inside the tag:
    void * QXmlReader:roperty ( const QString & name, bool * ok = 0 ) const

    That value is "Void *", how do I convert this to QString ?

  2. #2
    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: Xml parsing

    For short xml documents it might be better to use QDomDocument approach as the memory overhead is minimal and it's much easier to operate using DOM.

    If you insist on using QXmlReader approach then the "property()" method won't help you - it is for retrieving properties for the parser, not tag contents of the xml file. I'm not sure, as I never used SAX to parse an XML file, but I think you need to set the contents handler to be able to retrieve data from the file.

  3. #3
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Xml parsing

    Ok, QDomDocument is fine, the question is:

    How can I verift with the QDomDocument class that the XML is well formed ?

  4. #4
    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: Xml parsing

    I think QDomDocument::setContent() will return false in such situation.

  5. #5
    Join Date
    Apr 2006
    Location
    Minsk, Belarus
    Posts
    33
    Thanks
    2
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Xml parsing

    Yes, and even more: it will return additional information in other parameters of this method (where it happened and why)

    Qt Code:
    1. QString errorStr;
    2. int errorLine;
    3. int errorColumn;
    4.  
    5. if (!doc.setContent(&file, true, &errorStr, &errorLine, &errorColumn))
    6. {
    7. //handling error here
    8. file.close();
    9. return false;
    10. }
    11.  
    12. file.close();
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 15th December 2006 at 11:49. Reason: missing [code] tags

Similar Threads

  1. parsing QtableWidget from a QStackedWidget
    By rosmarcha in forum Qt Programming
    Replies: 10
    Last Post: 13th October 2006, 14:36
  2. Config file parsing
    By Vash5556 in forum Qt Programming
    Replies: 2
    Last Post: 10th September 2006, 23:11
  3. Parsing of Text files in Qt
    By shailesh in forum Qt Programming
    Replies: 3
    Last Post: 21st April 2006, 15:35
  4. HTML Parsing
    By awalesminfo in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2006, 11:31
  5. Trouble parsing using simple QRegExp
    By johnny_sparx in forum Qt Programming
    Replies: 4
    Last Post: 24th February 2006, 00:42

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.