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)

    @<?xml version="1.0" standalone="yes"?>
    <MaterialDetails Descrip="Material-2">
    <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-1">
    <Ref> 70 </Ref>
    <Min> 70 </Min>
    <Max> 70 </Max>
    <ColdTrans> 70 </ColdTrans>
    <HotTrans> 70 </HotTrans>
    <ParameterVal> 11 5 1.05e+07 </ParameterVal>
    </MaterialDetails>@



  • Hi,
    one option is to use XPath as filter, so you will filter out stuff you DONT WANT and store the result.



  • Thanks for giving reply .
    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 .



  • Hi,
    there is nothing you need to implement, Qt supports XPath,XQuery.. e.g. to delete wanted node just use( your example was missing root node, so I have added node xml

    /xml/MaterialDetails[@Descrip!='Material-2']

    see http://www.w3schools.com/xquery/xquery_example.asp


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.