Results 1 to 3 of 3

Thread: Performance Issue - Reading XML Values with 50-70 entry.

  1. #1
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Performance Issue - Reading XML Values with 50-70 entry.

    Hi,

    I want to read the values from the reg.xml file. I tried in several methods using FirstChild.NodeValue()/NextSibling.Nodevalue/NextSiblingbyelements etc.,
    The working code is down below. But the code seems to be lengthy and suspect some thing shortcut must be there to extract the values.
    Not like converting to QNodeList,assisgn to domNode and again Qstring.

    Is this code is right, Since If 50-70 xml enteries there, Then there will be performance issue. Kindly suggest.

    reg.xml
    -----------=
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <Download>
    3. <Maps MapSysID="0">
    4. <Title>MINOffice</Title>
    5. <itemId>dc96f92c410d4b93f0</itemId>
    6. <description>General map - 1 used for testing including thumbnail</description>
    7. <created>Wed Aug 31 09:38:49 2016 GMT+0100</created>
    8. <modified>Wed Aug 31 09:56:07 2016 GMT+0100</modified>
    9. <owner>manoharmdev</owner>
    10. <url>http://www.arssd.com/sharing/rest/content/items/dc96f92c410d4b93f0</url>
    11. <thumbnailUrl>http://www.arssd.com/sharing/rest/content/items/dc96f92c410d4b93f0/info/thumbnail/ThumbNail2.jpg</thumbnailUrl>
    12. <size>-1</size>
    13. <IsActive>1</IsActive>
    14. <EntryDate>Tuesday, October 04, 2016</EntryDate>
    15. </Maps>
    16. <Maps MapSysID="1">
    17. <Title>Prefecture</Title>
    18. <itemId>83d1c9aaf9d04e60a8c67</itemId>
    19. <description>CAR map-2 for testing purpose</description>
    20. <created>Wed Aug 31 09:52:23 2016 GMT+0100</created>
    21. <modified>Wed Aug 31 09:54:59 2016 GMT+0100</modified>
    22. <owner>manoharmdev</owner>
    23. <url>http://www.arssd.com/sharing/rest/content/items/83d1c9aaf9d04e60a8c67</url>
    24. <thumbnailUrl>http://www.arssd.com/sharing/rest/content/items/83d1c9aaf9d04e60a8c67/info/thumbnail/ThumbNail2.jpg</thumbnailUrl>
    25. <size>-1</size>
    26. <IsActive>1</IsActive>
    27. <EntryDate>Tuesday, October 04, 2016</EntryDate>
    28. </Maps>
    29. </Download>
    To copy to clipboard, switch view to plain text mode 

    C++ code for reading the xml
    ----------------------------------------------:
    Qt Code:
    1. QDomNodeList objQDomNodeListOne = docElem.elementsByTagName("Maps");
    2. QDomNode objQDomNodeone = objQDomNodeListOne.at(0);
    3. int intDomNode = objQDomNodeListOne.count();
    4.  
    5. QString strTitle ;
    6. QString strItemId ;
    7. QString strDescription;
    8. QString strCreated ;
    9. QString strModified ;
    10. QString strOwner ;
    11. QString strUrl ;
    12. QString strThumbnailUrl;
    13. QString strSize;
    14. QString strIsActive;
    15. QString strEntryDate;
    16.  
    17.  
    18. for(int i = 0; i < objQDomNodeListOne.count(); i++)
    19. {
    20. QDomNode elm = objQDomNodeListOne.at(i);
    21. if(elm.isElement())
    22. {
    23. QDomElement e = elm.toElement();
    24.  
    25. QDomNodeList qNdlstTitle = e.elementsByTagName("Title");
    26. QDomNodeList qNdlstitemId = e.elementsByTagName("itemId");
    27. QDomNodeList qNdlstdescription = e.elementsByTagName("description");
    28. QDomNodeList qNdlstcreated = e.elementsByTagName("created");
    29. QDomNodeList qNdlstmodified = e.elementsByTagName("modified");
    30. QDomNodeList qNdlstowner = e.elementsByTagName("owner");
    31. QDomNodeList qNdlsturl = e.elementsByTagName("url");
    32. QDomNodeList qNdlstthumbnailUrl = e.elementsByTagName("thumbnailUrl");
    33. QDomNodeList qNdlstsize = e.elementsByTagName("size");
    34. QDomNodeList qNdlstIsActive = e.elementsByTagName("IsActive");
    35. QDomNodeList qNdlstEntryDate = e.elementsByTagName("EntryDate");
    36.  
    37.  
    38.  
    39. QDomNode qNodeTitle = qNdlstTitle.at(0);
    40. QDomNode qNodeitemId = qNdlstitemId.at(0);
    41. QDomNode qNodedescription = qNdlstdescription.at(0);
    42. QDomNode qNodecreated = qNdlstcreated.at(0);
    43. QDomNode qNodemodified = qNdlstmodified.at(0);
    44. QDomNode qNodeowner = qNdlstowner.at(0);
    45. QDomNode qNodeurl = qNdlsturl.at(0);
    46. QDomNode qNodethumbnailUrl = qNdlstthumbnailUrl.at(0);
    47. QDomNode qNodesize = qNdlstsize.at(0);
    48. QDomNode qNodeIsActive = qNdlstIsActive.at(0);
    49. QDomNode qNodeEntryDate = qNdlstEntryDate.at(0);
    50.  
    51.  
    52.  
    53. strTitle = qNodeTitle.firstChild().nodeValue();
    54. strItemId = qNodeitemId.firstChild().nodeValue();
    55. strDescription = qNodedescription.firstChild().nodeValue();
    56. strCreated = qNodecreated.firstChild().nodeValue();
    57. strModified = qNodemodified.firstChild().nodeValue();
    58. strOwner = qNodeowner.firstChild().nodeValue();
    59. strUrl = qNodeurl.firstChild().nodeValue();
    60. strThumbnailUrl = qNodethumbnailUrl.firstChild().nodeValue();
    61. strSize = qNodesize.firstChild().nodeValue();
    62. strIsActive = qNodeIsActive.firstChild().nodeValue();
    63. strEntryDate = qNodeEntryDate.firstChild().nodeValue();
    64.  
    65. }
    66. }
    To copy to clipboard, switch view to plain text mode 
    reply quote 0
    Last edited by anda_skoa; 6th October 2016 at 16:32. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,387
    Thanks
    247
    Thanked 687 Times in 677 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Performance Issue - Reading XML Values with 50-70 entry.

    Except for the fact that you are overwriting the strings each time you go through the loop, there is nothing wrong with this code. With the mostly flat structure of this XML, there isn't really any other way to convert it if you use QDomDocument methods. With 50 - 70 entries, I do not think you need to worry about performance. This is a tiny XML file.

    Please use [CODE] tags when posting source code. My signature (below) explains how.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Performance Issue - Reading XML Values with 50-70 entry.

    And if you want to worry about performance, use a performant approach to parsing XML, such as QXmlStreamReader.

    Cheers,
    _

Similar Threads

  1. Reading values from XML
    By Srikanth.Togara in forum Newbie
    Replies: 6
    Last Post: 14th June 2016, 03:25
  2. Replies: 0
    Last Post: 22nd September 2015, 21:31
  3. reading the latest entry text from QplaintextEdit
    By PHANI in forum Qt Programming
    Replies: 3
    Last Post: 6th February 2012, 11:30
  4. QextSerialPort reading error: wrong values
    By Lawand in forum Qt Programming
    Replies: 9
    Last Post: 6th May 2009, 19:29
  5. Reading values from file to array
    By Jeo_ in forum Newbie
    Replies: 0
    Last Post: 24th April 2009, 18:05

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.