Regex to replace " with " only if it’s not in another "

I’m converting an encoded XML document to its original format

string myXml = oldXml.Replace("&lt;", "<").Replace("&amp;", "&")
                                                   .Replace("&gt;", ">")
                                                   .Replace("&quot;", """)
                                                   .Replace("&apos;", "'");

It works fine. However I want to exclude &quot; if its in another &quot;.


Original XML

//Note the title value
<v:shape id="_x0000_i1025" title="a&quot; title &quot;b"> </v:shape>

Encoded XML

&lt;v:shape id=&quot;_x0000_i1025&quot; title=&quot;a&quot; title &quot;b&quot;&gt; &lt;/v:shape&gt;

Recovered XML after replace

//Note the title value
<v:shape id="_x0000_i1025" title="a" title "b"> </v:shape>

As you can see the inside &quot; shouldn’t be convert to ". So how can I do the replace with Regex so that it doesn’t replace the inside &quot;

Thank you

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.