Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24

Thread: How to parse this xml file?

  1. #21
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to parse this xml file?

    I have found the solution>>. Thanks for your help.
    Qt Code:
    1. for ( node = docElem.firstChild();!node.isNull();node = node.nextSibling()) {
    2.  
    3. while(node.toElement().tagName() == "folder")
    4. {
    5. firmFolder += node.toElement().attribute("name");
    6. firmFolder += "/";
    7. node = node.firstChild();
    8. }
    9. while(node.toElement().tagName() == "file")
    10. {
    11. firmFiles += node.toElement().attribute("name");
    12. firmFiles += " ";
    13. saveNode = node;
    14. node = node.nextSibling();
    15. }
    16.  
    17. //node = docElem.firstChild();
    18. node = saveNode.parentNode();
    19.  
    20. while(node.parentNode().toElement().tagName() != "package"){
    21. node = node.parentNode();
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #22
    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: How to parse this xml file?

    That's a really bad solution.

    Here is a better one:

    Implement the following function called "getPath"
    1. Go to first child element with tag "folder"
    2. If there is no such tag, go to first child element with tag "file", otherwise skip to step 6
    3. If there is no such tag, return an empty list
    4. Add the name of the file to a list
    5. Go to next sibling of the tag that is also tagged "file", add it to the list and keep doing that until you run out of "file" tags. Then return a list of files found.
    6. Call getPath on the folder tag.
    7. For each string returned by getPath, prepend it with the folder name just found and a directory separator
    8. Repeat for all sibling "folder" tags
    9. Return a list of found entries.

    If you call getPath on the parent node of the "folder" nodes, you'll get a complete list of entries in the package.
    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.


  3. #23
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to parse this xml file?

    Could you modify my code and describe how it should be?

  4. #24
    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: How to parse this xml file?

    No, I would have to discard your code and write a new one from scratch. And if I wanted to, I would have already done that. Learn your lesson and do it yourself.
    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.


Similar Threads

  1. How to parse QML file from QT C++
    By AbinaThomas in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2012, 09:47
  2. Parse huge XML file
    By juracist in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2012, 01:54
  3. Replies: 13
    Last Post: 21st June 2006, 21:22
  4. How to parse this XML file ?
    By probine in forum Qt Programming
    Replies: 7
    Last Post: 4th April 2006, 09:05
  5. Parse a pickle file
    By karye in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2006, 17:02

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.