Results 1 to 3 of 3

Thread: Why are only some XML nodes (found by elementsByTagName() ) removed in QDomDocument?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2008
    Posts
    68

    Exclamation Why are only some XML nodes (found by elementsByTagName() ) removed in QDomDocument?

    Hello,

    I am trying to open an existing XML file, remove some nodes ( or branches ) and save the result as a new XML file. following is the code. In the original XML file, there are one "WindowLevelMap" node and many "ImageGroup" and "ImageVector" nodes. With the following code, in the new file, "WindowLevelMap" node is removed. However, only some "ImageGroup" nodes and "ImageVector" nodes are removed.

    What is the problem?

    thank you in advance!

    Qt Code:
    1. ...
    2. // Create DOM;
    3. QDomDocument doc("testDoc");
    4. QFile orgFile(strOrignalXMLFile);
    5. if (!orgFile.open(QIODevice::ReadWrite))
    6. return Command::Failure;
    7. if (!doc.setContent(&orgFile))
    8. {
    9. orgFile.close();
    10. return Command::Failure;
    11. }
    12.  
    13. // Remove useless nodes;
    14. QDomNodeList toRemoveNodeList;
    15. int idx;
    16.  
    17. // --
    18. toRemoveNodeList = doc.elementsByTagName( QString("WindowLevelMap"));
    19. for( idx = 0; idx < toRemoveNodeList.size(); idx++)
    20. {
    21. QDomNode parentNode = toRemoveNodeList.at(idx).parentNode();
    22. parentNode.removeChild( toRemoveNodeList.at(idx) );
    23. }
    24.  
    25. // --
    26. toRemoveNodeList = doc.elementsByTagName( QString("ImageGroup"));
    27. for( idx = 0; idx < toRemoveNodeList.size(); idx++)
    28. {
    29. QDomNode parentNode = toRemoveNodeList.at(idx).parentNode();
    30. parentNode.removeChild( toRemoveNodeList.at(idx) );
    31. }
    32.  
    33. // --
    34. toRemoveNodeList = doc.elementsByTagName( QString("ImageVector"));
    35. for( idx = 0; idx < toRemoveNodeList.size(); idx++)
    36. {
    37. QDomNode parentNode = toRemoveNodeList.at(idx).parentNode();
    38. parentNode.removeChild( toRemoveNodeList.at(idx) );
    39. }
    40.  
    41.  
    42. // Save result;
    43. const int Indent = 4;
    44. QFile filteredFile(strFilteredXMLFile);
    45. if (!filteredFile.open(QIODevice::WriteOnly))
    46. return Command::Failure;
    47.  
    48. QTextStream out(&filteredFile);
    49. doc.save(out, Indent);
    50. filteredFile.close();
    51.  
    52. ...
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2008
    Posts
    68

    Default Re: Why are only some XML nodes (found by elementsByTagName() ) removed in QDomDocum

    Can anyone help!

    Thank you!

  3. #3
    Join Date
    Nov 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why are only some XML nodes (found by elementsByTagName() ) removed in QDomDocum

    Did you get a solution to this problem?

    I seem to be stuck with this problem too.

Similar Threads

  1. Split QDomDocument to new QDomDocument
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 28th January 2009, 09:59
  2. QDomDocument inside other QDomDocument
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2008, 15:27
  3. QDomElement::elementsByTagName()
    By manojmka in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2008, 11:43
  4. viewing removed but not submitted rows
    By maxel in forum Qt Programming
    Replies: 6
    Last Post: 6th October 2006, 17:20
  5. QDomDocument - closed nodes?
    By naresh in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 08:10

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
  •  
Qt is a trademark of The Qt Company.