增加xml:id,1用findepad ++查找/替换

时间:2016-06-17 16:19:48

标签: regex xml notepad++

一个简单而短暂的问题。我使用notepad ++作为我的xml表。 Heres是一个示例结构。

<category xml:id="S0078">
   <catDesc>
     <term>Test</term>
   </catDesc>
</category>
<category xml:id="S0079">
   <catDesc>
     <term>Test</term>
   </catDesc>
</category>

我的问题是如何使用简单的搜索和替换命令将id从S0078增加到S300。我试着使用正则表达式。但这不起作用。有人有想法吗?

1 个答案:

答案 0 :(得分:1)

使用XML感知工具修改XML。例如,在xsh中,您可以执行

open file.xml ;
for my $id in //category[
    (@xml:id | preceding-sibling::category/@xml:id) = 'S0078'
][
    (@xml:id | following-sibling::category/@xml:id) = 'S0300'
]/@xml:id
    set $id/. { $id->value =~ s/([0-9]+)/$1+1/er } ;
save :b ;