Results 1 to 4 of 4

Thread: Removing specific node in XML .

  1. #1
    Join Date
    May 2012
    Location
    India
    Posts
    51
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Removing specific node in XML .

    I have created XML file using QXmlStreamWriter .

    How can i delete one MaterialDetails node based on some key value (here it is descrip)

    Qt Code:
    1. <?xml version="1.0" standalone="yes"?>
    2. <MaterialDetails Descrip="Material-1">
    3. <Ref> 70 </Ref>
    4. <Min> 70 </Min>
    5. <Max> 70 </Max>
    6. <ColdTrans> 70 </ColdTrans>
    7. <HotTrans> 70 </HotTrans>
    8. <ParameterVal> 11 5 1.03e+07</ParameterVal>
    9. </MaterialDetails>
    10.  
    11. <MaterialDetails Descrip="Material-2">
    12. <Ref> 70 </Ref>
    13. <Min> 70 </Min>
    14. <Max> 70 </Max>
    15. <ColdTrans> 70 </ColdTrans>
    16. <HotTrans> 70 </HotTrans>
    17. <ParameterVal> 11 5 1.05e+07 </ParameterVal>
    18. </MaterialDetails>
    To copy to clipboard, switch view to plain text mode 
    Last edited by riarioriu3; 12th September 2012 at 14:37.

  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: Removing specific node in XML .

    Skip that node when writing the xml stream with QXmlStreamWriter.
    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. #3
    Join Date
    May 2012
    Location
    India
    Posts
    51
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Removing specific node in XML .

    Thanks wyosta for giving reply . you helped me a lot in my prev posts ..
    I have given Desc attribute which can be used as a id . Instead of writing everything again , is there any concept like it will search the tag based on desc attribute , if it finds its value as Material-2 then it will delete the MaterialDetails node .

  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: Removing specific node in XML .

    You can use QDomDocument to load the whole xml tree into memory and then use QDomNode::removeChild() to remove a node. Just remember to write the resulting tree to a file again and possibly truncate the file.
    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.


  5. The following user says thank you to wysota for this useful post:

    riarioriu3 (25th September 2012)

Similar Threads

  1. Designing a Node Editor (Hint: Blender Node Editor)
    By Mind Calamity in forum Qt Programming
    Replies: 4
    Last Post: 5th October 2011, 16:22
  2. Replies: 0
    Last Post: 31st August 2011, 15:54
  3. Replies: 5
    Last Post: 14th February 2011, 14:06
  4. Inserting node to Xml file
    By vajindarladdad in forum Newbie
    Replies: 2
    Last Post: 13th April 2009, 11:34
  5. how to justfy a node is leaf node or not
    By weixj2003ld in forum Qt Programming
    Replies: 4
    Last Post: 9th April 2009, 07:40

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.