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)
Code:
<?xml version="1.0" standalone="yes"?>
<MaterialDetails Descrip="Material-1">
<Ref> 70 </Ref>
<Min> 70 </Min>
<Max> 70 </Max>
<ColdTrans> 70 </ColdTrans>
<HotTrans> 70 </HotTrans>
<ParameterVal> 11 5 1.03e+07</ParameterVal>
</MaterialDetails>
<MaterialDetails Descrip="Material-2">
<Ref> 70 </Ref>
<Min> 70 </Min>
<Max> 70 </Max>
<ColdTrans> 70 </ColdTrans>
<HotTrans> 70 </HotTrans>
<ParameterVal> 11 5 1.05e+07 </ParameterVal>
</MaterialDetails>
Re: Removing specific node in XML .
Skip that node when writing the xml stream with QXmlStreamWriter.
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 .
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.