Servitus
Servitus

Reputation: 1

Find and replace with asterisk character

This is not really a programming question, I just have an XML file like this:

<product>
    <id>123</id>
</product>
<product>
    <id>245</id>
</product>
<product>
    <id>356</id>
</product>

I want to find all id's and replace them with just one "0". As ID's are different, I cannot use notepad++ because it can't find like <id>*</id> so how can I do it? The file is really long.

Upvotes: 0

Views: 861

Answers (3)

Ravi Sen
Ravi Sen

Reputation: 101

Note: Answering as per the XML structure given.

Use Notepad++ Regular expression and replace \d+ with 0.

enter image description here

Upvotes: 1

Andrea
Andrea

Reputation: 12375

You can replace the tag content even in Notepad++ with a Regex-based find&replace:

Search:

<id>[^<>]+</id>

and replace it with:

<id>0</id>

This should be the find and replace window (remember to enable "Regular Expression"):

enter image description here

XML before replacing:

enter image description here

XML after replacing:

enter image description here

Upvotes: 0

choroba
choroba

Reputation: 241918

Use an XML-aware tool to process XML. For example, in xsh you can just write

open file.xml ;
for //product/id set text() 0 ;
save :b ;

Upvotes: 1

Related Questions