xpath - xmlstarlet delete all elements except one from xml data feed -


on debian vps, want keep element categoryname mobile phones , delete other elements having category names such mobile accessories laptops etc. total 20 different category names. xml file size big 800 mb.

xmlstarlet el -u sd.xml products products/product products/product/brand products/product/categoryname products/product/categorypathasstring 

here sample xml :

<products> <product>    <productid>92545172</productid>    <productsku>630348288360</productsku>    <productname>self snap aux connected selfie stick</productname>    <productdescription>this product charge free </productdescription>    <productprice>353.00</productprice>    <productpricecurrency>inr</productpricecurrency>    <wasprice>649.00</wasprice>    <discountedprice>0.00</discountedprice>    <producturl>http://clk</producturl>    <pid>8053</pid>    <mid>159526</mid>    <productimagelargeurl>http://</productimagelargeurl>    <stockavailability>in stock</stockavailability>    <brand>self snap</brand>    <categoryname>camera accessories</categoryname>    <categorypathasstring>root|cameras &amp; accessories|camera accessories|</categorypathasstring> </product> <product>    <productid>29911116</productid>    <productsku>647266238</productsku>    <productname>philips 40pfl5059/v7 40 inches full hd led television</productname>    <productdescription>led display resolution : 1920 x 1080</productdescription>    <productprice>30196.00</productprice>    <productpricecurrency>inr</productpricecurrency>    <wasprice>39800.00</wasprice>    <discountedprice>0.00</discountedprice>    <producturl>http://clk</producturl>    <pid>8053</pid>    <mid>159526</mid>    <productimagelargeurl>http://n1</productimagelargeurl>    <stockavailability>in stock</stockavailability>    <brand>philips</brand>    <categoryname>televisions</categoryname>    <categorypathasstring>root|tvs, audio &amp; video|televisions|</categorypathasstring> </product> <product>    <productid>93959216</productid>    <productsku>683203029</productsku>    <productname>micromax canvas beat a114r</productname>    <productdescription>type : multisim sim : dual sim os version : android </productdescription>    <productprice>7999.00</productprice>    <productpricecurrency>inr</productpricecurrency>    <wasprice>9990.00</wasprice>    <discountedprice>0.00</discountedprice>    <producturl>http://clk</producturl>    <pid>8053</pid>    <mid>159526</mid>    <productimagelargeurl>http://n1</productimagelargeurl>    <stockavailability>in stock</stockavailability>    <brand>micromax</brand>    <categoryname>mobile phones</categoryname>    <categorypathasstring>root|mobiles &amp; tablets|mobile phones|</categorypathasstring> </product> </products> 

it isn't clear without sample xml , expected result xml. assuming want delete elements named categoryname having inner text not equals "mobile phones", can try using xpath :

/products/product/categoryname[. != 'mobile phones'] 

turned out want delete <product> element having child element <categoryname> value not equals "mobile phones". in case, can try following xpath :

/products/product[categoryname != 'mobile phones'] 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -