开发者

Can I tell HTML agility pack to NOT fix some types of invalid markup?

开发者 https://www.devze.com 2023-04-12 10:03 出处:网络
I have HTML agility pack modifying some of my html within the umbraco CMS, however umbraco uses some non-standard html-oid (See below)

I have HTML agility pack modifying some of my html within the umbraco CMS, however umbraco uses some non-standard html-oid (See below)

The problem is after the html agility pack replaces the closing slash with a question mark.

macro tag before html agility pack开发者_运维问答:

<?UMBRACO_MACRO macroAlias="RandomMacroTest" />

macro tag after html agility pack:

<?umbraco_macro macroalias="RandomMacroTest"?>

Any clues how I could get around this? Tell Html Agility pack to ignore this tag? I've looked at it's various options and none of them seem to apply.

Last resort: to go back and re-fix the macro tags with a regex replace, but that seems a bit messy.


Enable the OptionWriteEmptyNodes option on the document. It should preserve that tag.

var htmlStr = @"<?UMBRACO_MACRO macroAlias=""RandomMacroTest"" />";
var doc = new HtmlDocument
{
    OptionOutputOriginalCase = true,
    OptionWriteEmptyNodes = true,
};
doc.LoadHtml(htmlStr);
doc.Save(Console.Out);

You will have the output:

<?UMBRACO_MACRO macroalias="RandomMacroTest" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号