Results 1 to 3 of 3

Thread: DOM setContent first or last?

  1. #1
    Join Date
    Aug 2011
    Location
    Finland
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question DOM setContent first or last?

    When reading an XML file, which of the following methods should I use?

    (1) Open the file, .setContent(file), parse it in nested loops where I check tagnames with string comparisons and move along with .nextSibling() and .firstChild().

    (2) Construct a tree object starting with the root element and adding child elements as I expect them to appear in the file, open the file, .setContent(file), and BAM the previously contructed element objects (and their attributes) now contain the data I need.

    If (2) is advisable I could use sample code for the first few elements... how are lists containing an unkown amount of elements with the same tagname (different attribute values) handled?

  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: DOM setContent first or last?

    What exactly do you want to do with the data? Because (2) seems pretty useless for me, because that is what QDomDocument already does. Your can use QDomDocument::elementsByTagName() or similar to get the value of a specific node or use XQuery.

  3. #3
    Join Date
    Aug 2011
    Location
    Finland
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DOM setContent first or last?

    Well, I'd put some data to non-xml member variables and display some directly in the UI... The idea with (2) is that unlike in (1), the data would be in local variables (QDomElement objects or maybe lists thereof) whose names I'd already know, thereby removing the need to traverse the structure with if-tagname comparisons and while-nextsibling loops.

Similar Threads

  1. Replies: 6
    Last Post: 6th September 2010, 13:38
  2. Strange error: doc.setContent(data) returns false
    By jiveaxe in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2009, 01:38

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.