I have an xml document with blocks that look like this:
<integer name="Activation" value="0"/>
<boolean name="CanBuy" value="true"/>
<integer name="Cost" value="57600"/>
<integer name="CostBuy" value="86400"/>
<string name="Country" value="USA"/>
<string name="DateBuy" value="01.01.1940"/>
<string name="ID" value="20ABandage"/>
<integer name="MinTime" value="300"/>
<integer name="ProdUnit" value="50"/>
I'd like to replace values based on Country
If = '<string name="Country" value="USA"/>'
then
<integer name="Cost" value="1"/>
<integer name="CostBuy" value="1"/>
<string name="DateBuy" value="01.01.2018"/>
<integer name="MinTime" value="1"/>
output would look like this
<integer name="Activation" value="0"/>
<boolean name="CanBuy" value="true"/>
<integer name="Cost" value="1"/>
<integer name="CostBuy" value="1"/>
<string name="Country" value="USA"/>
<string name="DateBuy" value="01.01.2018"/>
<string name="ID" value="20ABandage"/>
<integer name="MinTime" value="1"/>
<integer name="ProdUnit" value="50"/>
Thanks
Steve
btw: I just bought a MacBook - Is there an IOS version of TextPad?
Thanks again
XML replace multiple values if XML block contains X
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Re: XML replace multiple values if XML block contains X
That's better done programmatically than thru regular expressions. For precisely the cases you provided it would go like this:
Search for:Replace with: ...but I highly doubt your XML looks exactly/always like this.
Search for:
Code: Select all
(<integer name="Cost" value=)"[^"]+"(/>\n<integer name="CostBuy" value=)"[^"]+"(/>\n<string name="Country" value="USA"/>\n<string name="DateBuy" value=)"[^"]+"(/>\n<string name="ID" value="[^"]+"/>\n<integer name="MinTime" value=)"[^"]+"(/>)
Code: Select all
\1"1"\2"1"\3"01.01.2018"\4"1"\5