Remove specific xml elements using PowerShell -
i have following xml:
<ns1:pricemaintenancerequest xmlns:ns1="http://retalix.com/r10/services" majorversion="2" minorversion="0" fixversion="0"> <ns1:header> <ns1:messageid>1234</ns1:messageid> <ns1:bulk unitofwork="false"/> </ns1:header> <ns1:productprice businessunitid="9200" action="addorupdate"> <ns1:productid>2840000133</ns1:productid> <ns1:price action="addupdate" sequence="1234"> <ns1:unitofmeasurecode>ea</ns1:unitofmeasurecode> <ns1:effectivedatetimestamp>2012-09-20t00:00:00</ns1:effectivedatetimestamp> <ns1:enddatetimestamp>2056-12-12t23:59:00</ns1:enddatetimestamp> <ns1:catalogprice currency="usd">4.2900</ns1:catalogprice> <ns1:batchid>491364c5-73f5-45a4-8355-79cc0a720ea0</ns1:batchid> <ns1:changestatus>na</ns1:changestatus> </ns1:price> </ns1:productprice> <ns1:productprice businessunitid="90" action="addorupdate"> <ns1:productid>2840000133</ns1:productid> <ns1:price action="addupdate" sequence="1234"> <ns1:unitofmeasurecode>ea</ns1:unitofmeasurecode> <ns1:effectivedatetimestamp>2012-09-20t00:00:00</ns1:effectivedatetimestamp> <ns1:enddatetimestamp>2056-12-12t23:59:00</ns1:enddatetimestamp> <ns1:catalogprice currency="usd">4.2900</ns1:catalogprice> <ns1:batchid>491364c5-73f5-45a4-8355-79cc0a720ea0</ns1:batchid> <ns1:changestatus>na</ns1:changestatus> </ns1:price> </ns1:productprice> <ns1:productprice businessunitid="90" action="addorupdate"> <ns1:productid>2840000133</ns1:productid> <ns1:price action="addupdate" sequence="1234"> <ns1:unitofmeasurecode>ea</ns1:unitofmeasurecode> <ns1:effectivedatetimestamp>2012-09-20t00:00:00</ns1:effectivedatetimestamp> <ns1:enddatetimestamp>2056-12-12t23:59:00</ns1:enddatetimestamp> <ns1:catalogprice currency="usd">4.2900</ns1:catalogprice> <ns1:batchid>491364c5-73f5-45a4-8355-79cc0a720ea0</ns1:batchid> <ns1:changestatus>na</ns1:changestatus> </ns1:price> </ns1:productprice> </ns1:pricemaintenancerequest>
i need remove nodes businessunitid="90". in example, end this:
<ns1:pricemaintenancerequest xmlns:ns1="http://retalix.com/r10/services" majorversion="2" minorversion="0" fixversion="0"> <ns1:header> <ns1:messageid>1234</ns1:messageid> <ns1:bulk unitofwork="false"/> </ns1:header> <ns1:productprice businessunitid="9200" action="addorupdate"> <ns1:productid>2840000133</ns1:productid> <ns1:price action="addupdate" sequence="1234"> <ns1:unitofmeasurecode>ea</ns1:unitofmeasurecode> <ns1:effectivedatetimestamp>2012-09-20t00:00:00</ns1:effectivedatetimestamp> <ns1:enddatetimestamp>2056-12-12t23:59:00</ns1:enddatetimestamp> <ns1:catalogprice currency="usd">4.2900</ns1:catalogprice> <ns1:batchid>491364c5-73f5-45a4-8355-79cc0a720ea0</ns1:batchid> <ns1:changestatus>na</ns1:changestatus> </ns1:price> </ns1:productprice> </ns1:pricemaintenancerequest>
how do powershell?
need load files containing xml directory, manipulate them, , save them.
thanks lot
you can this:
get-childitem -path "c:\folderwithxmls" -filter "*.xml" | foreach-object { $path = $_.fullname $xml = [xml](get-content $path) $xml.pricemaintenancerequest.productprice | ? { $_.businessunitid -eq "90" } | % { #remove node $xml.pricemaintenancerequest.removechild($_) } $xml.save($path) }
Comments
Post a Comment