PDA

View Full Version : Removing specific node in XML .



riarioriu3
12th September 2012, 14:30
I have created XML file using QXmlStreamWriter .

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


<?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>

wysota
12th September 2012, 16:08
Skip that node when writing the xml stream with QXmlStreamWriter.

riarioriu3
13th September 2012, 12:56
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 .

wysota
13th September 2012, 13:14
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.