c# - .Net HTMLAgilityPack 正在向标签属性添加空引号
问题描述
我目前正在使用 HMLAgilityPack 来编辑 html 文件。
我的模板有这段 html:
<model-viewer class="viewer" id="viewer1" ar ar-modes="scene-viewer quick-look" ar-scale="auto" environment-image="neutral" src="mymodel.glb" camera-controls auto-rotate></model-viewer>
但是,当我编辑并保存此文档时,它会在此标记的某些部分添加一个空属性。例如,保存的 html 如下所示,其中 ar、camera-controls 和 auto-rotate 添加了空引号。
<model-viewer class="viewer" id="viewer1" ar="" ar-modes="scene-viewer quick-look" ar-scale="auto" environment-image="neutral" src="mymodel.glb" camera-controls="" auto-rotate=""></model-viewer>
我该如何停止
ar
在模型查看器标签中成为
ar=""
?
谢谢
解决方案
https://github.com/zzzprojects/html-agility-pack/issues/422
Set htmlDoc.GlobalAttributeValueQuote = AttributeValueQuote.WithoutValue
var html = @"<!DOCTYPE html>
<html>
<body a b c>
</body>
</html> ";
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
htmlDoc.GlobalAttributeValueQuote = AttributeValueQuote.WithoutValue;
htmlDoc.Save(@"./test.html");
// <!DOCTYPE html>
// <html>
// <body a b c>
// </body>
// </html>
推荐阅读
- java - Java多态练习
- slim-3 - Slim 3 双输出使用自己的视图文件
- java - org.openqa.selenium.NoSuchElementException:无法定位元素错误
- azure-devops - VSTS 构建定义上的“批处理脚本”任务未激活 Conda 环境
- javascript - 自动排序无法正常工作
- ember.js - 当问题出现在 node_module 的插件中时,如何解决 ember cli 问题?
- node.js - 如何在快速路由中返回多个承诺的结果?
- amazon-web-services - 如何让 Amazon Cognito 托管 UI 提示输入 TOTP?
- css - 具有生成的样式数据绑定的参考资产
- java - 将标签文本值绑定到外部文件的字符串属性