I have some cases where my clients send me a html string with some elements attributes not so correctly structured. Like this:
<img src="../imgTest.jpg" alt="Something "quoted here, or here"">
How can I dynamically change these cases to something like this next?
<img src="../imgTest.jpg" alt="Something 'quoted here, or here'">
I need this html not to show on browser but to do some operations with it.
I'm using HtmlAgilityPack to control html problems but for these cases it changes my html string to this and it isn't what I want:
<img src="../imgTest.jpg" alt="Something" quoted="" here,="" or="" here="">
My code with HtmlAgilityPack:
var htmlDoc = new HtmlDocument();
htmlDoc.OptionFixNestedTags = true;
htmlDoc.LoadHtml(myHtmlStr);
var htmlError = htmlDoc.ParseErrors.SafeAny();
if (!htmlError)
myHtmlStr = htmlDoc.DocumentNode.InnerHtml;
(?<=<\w+\s[^<]*)(?<!\w+=)"(?!\s*/?>|\s+\w+=")
and replace with'
.(=\s*"[^=">]*)"([^=">]*)"([^=">]*")
and replace with$1'$2'$3
which is not very reliable :>