XML replace multiple values if XML block contains X

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
steve1040
Posts: 39
Joined: Fri Oct 13, 2006 2:19 am

XML replace multiple values if XML block contains X

Post by steve1040 »

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
User avatar
AmigoJack
Posts: 533
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Re: XML replace multiple values if XML block contains X

Post by AmigoJack »

That's better done programmatically than thru regular expressions. For precisely the cases you provided it would go 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=)"[^"]+"(/>)
Replace with:

Code: Select all

\1"1"\2"1"\3"01.01.2018"\4"1"\5
...but I highly doubt your XML looks exactly/always like this.
Post Reply