Sunday, 29 September 2013

How can i remove XML attribute with specific content with Regex?

How can i remove XML attribute with specific content with Regex?

I have huge amount XML files and I need to remove attributes with specific
content.
<Image Width="214.57"
Height="165"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Source="{DynamicResourceExtension
ResourceKey=images_4bd6348715-testImage.jpg}"
Canvas.Left="8"
Canvas.Top="24" />
First case:
Operator can enter images_4bd6348715-testImage.jpg and attribute Source
should be removed.
Attribute can have any name.
Second case:
Text can be inside node. Node can have any name:
<Image Width="214.57"
Height="165"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Canvas.Left="8"
Canvas.Top="24" >
<Image.Source2>
<DynamicResource>
<DynamicResource.ResourceKey>
images_4bd6348715-testImage.jpg
</DynamicResource.ResourceKey>
<DynamicResource>
</Image.Source2>
</Image>
In both cases i only know that inside attribe or node i will have
DynamicResource or DynamicResourceExtension
How can i do this with Regex query?

No comments:

Post a Comment