首页 > 解决方案 > 正则表达式:如何替换 xml 属性中的所有嵌套双引号

问题描述

我有这个xml,它可以在属性内嵌套双引号(未转义):

<test>
    <tag1 att1="This has "nested double quotes"">
        <tag2 att2="This also has a nested " double quotes"></tag2>
    </tag1>
</test>

我需要找到一个将选择所有嵌套双引号的正则表达式,在这种情况下

&quot;并用字符替换它们。最终的 xml 应如下所示:

<test>
    <tag1 att1="This has &quot;nested double quotes&quot;">
        <tag2 att2="This also has a nested &quot; double quotes"></tag2>
    </tag1>
</test>

是否可以使用正则表达式来实现这一点?

标签: regexxml

解决方案


推荐阅读