Super User Asked by paresh patil on January 26, 2021
I have a XML file with following data
<Shipment>
<Shipper>
<Name>Clothes</Name>
<Address1>Apparel Street</Address1>
<Country>GB</Country>
</Shipper>
<Shopper>
<Name>ABC</Name>
<Address1>Street 1</Address1>
<Country>IE</Country>
</Shopper>
</Shipment>
<Shipment>
<Shipper>
<Name>Clothes</Name>
<Address1>Apparel Street</Address1>
<Country>GB</Country>
</Shipper>
<Shopper>
<Name>XYZ</Name>
<Address1>Street 9</Address1>
<Country>US</Country>
</Shopper>
</Shipment>
I want to change only the Shopper addresses to specific one, like below
<Shipment>
<Shipper>
<Name>Clothes</Name>
<Address1>Apparel Street</Address1>
<Country>GB</Country>
</Shipper>
<Shopper>
<Name>ABC</Name>
<Address1>Wonderland</Address1>
<Country>CA</Country>
</Shopper>
</Shipment>
<Shipment>
<Shipper>
<Name>Clothes</Name>
<Address1>Apparel Street</Address1>
<Country>GB</Country>
</Shipper>
<Shopper>
<Name>XYZ</Name>
<Address1>Wonderland</Address1>
<Country>CA</Country>
</Shopper>
</Shipment>
Let me know if there is any easy way to resolve this using Find and replace option in Notepad++
thanks
(<Shopper>(?:(?!</Shopper>)[sS])+?<Address1>).+?(</Address1>[sS]+?<Country>).+?(</Country>)
$1Wonderland$2CA$3
. matches newline
Explanation:
( # group 1
<Shopper> # open tag
(?:(?!</Shopper>)[sS])+? # 1 or more any character, not greedy, and never encountered "</Shopper>"
<Address1> # open tag
) # end group 1
.+? # 1 or more any character but ewline, not greedy
( # group 2
</Address1> # close tag
[sS]+? # 1 or more any character, not greedy
<Country> # open tag
) # end group 2
.+? # 1 or more any character but newline
(</Country>) # group 3, end tag
Replacement:
$1 # content of group 1
Wonderland # literally
$2 # content of group 2
CA # literally
$3 # content of group 3
Screenshot (before):
Screenshot (after):
Correct answer by Toto on January 26, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP