xml - 从节点到字符串的 Scala XML 警告
问题描述
我的问题是关于scala.xml
从Node
类型到String
(使用任何方法buildString
或toString
方法)的转换。
当我将这种转换为标准输出时,我会收到有关输入的警告列表,如下所示:
line 2 column 2 - Warning: unknown attribute "myAttribute1"
line 3 column 9 - Warning: unknown attribute "myAttribute2"
line 6 column 9 - Warning: unknown attribute "myAttribute3"
line 7 column 13 - Warning: unknown attribute "myAttribute4"
line 7 column 13 - Warning: unknown attribute "myAttribute5"
line 13 column 25 - Warning: <th> attribute "width" has invalid value "3%"
line 15 column 36 - Warning: <th> attribute "width" has invalid value "5%"
line 17 column 36 - Warning: <th> attribute "width" has invalid value "3%"
line 19 column 36 - Warning: <th> attribute "width" has invalid value "15%"
line 21 column 36 - Warning: <th> attribute "width" has invalid value "3%"
line 23 column 36 - Warning: <th> attribute "width" has invalid value "3%"
line 25 column 36 - Warning: <th> attribute "width" has invalid value "3%"
line 27 column 36 - Warning: <th> attribute "width" has invalid value "3%"
line 29 column 36 - Warning: <th> attribute "width" has invalid value "3%"
line 35 column 22 - Warning: unknown attribute "data-col-count"
line 41 column 15 - Warning: inserting missing 'title' element
InputStream: Document content looks like HTML 4.01 Transitional
18 warnings, no errors were found!
The table summary attribute should be used to describe
the table structure. It is very helpful for people using
non-visual browsers. The scope and headers attributes for
table cells are useful for specifying which headers apply
to each table cell, enabling non-visual browsers to provide
a meaningful context for each cell.
For further advice on how to make your pages accessible
see "http://www.w3.org/WAI/GL". You may also want to try
"http://www.cast.org/bobby/" which is a free Web-based
service for checking URLs for accessibility.
所以,我的问题是是否有办法摆脱这种输出。生成这个的代码只是:
data.buildString(true).getBytes(StandardCharsets.UTF_8)
数据在哪里Scala.xml.Node
谢谢
编辑
我试图从来回解析Node
到String
REPL,但我没有收到任何警告。
对于解析,我使用XMLLooader
从 scala.xml扩展的自定义对象SAXParser
with setValidation(false)
。然后我只是loadString(input)
用来获取我的节点。
看看SAXParser
我在这里结束的文档:https://docs.oracle.com/javase/7/docs/api/org/xml/sax/helpers/DefaultHandler.html#warning(org.xml.sax.SAXParseException)在它说的地方,在默认情况下没有为警告提供任何操作。
解决方案
看起来您的输出来自 JTidy,就像这个关于删除警告的问题中描述的那样,或者可能是其他一些“整洁”的库。
当我尝试您的线路时:
data.buildString(true).getBytes(StandardCharsets.UTF_8)
它没有给我你得到的任何输出,也许程序的另一部分导致了这个?
推荐阅读
- c# - 如何在 C# 项目中使用 windows 命令行安装 Nuget 包?
- azure-devops - Azure DevOps 开始聊天没有响应单击
- sql - BigQuery:聚合对象数组。获取“不支持引用其他表的相关子查询”
- laravel - 超过 20 秒的最大执行时间
- python-3.x - Tensorflow (.pb) 格式到 Keras (.h5)
- hyperledger-fabric - Hyperledger Fabric CA 在启用 TLS 时向 Node SDK 发布错误的证书(错误的颁发者)
- git - 重命名或移动 Git 存储库中的项目模块并保留历史记录
- java - 使用 JSTL 遍历地图
- angularjs - Angular ng-click 未重定向到控制器模板 URL
- apache-nifi - GetFile/ListFile/FetchFile 可以配置为每个触发器重复列表吗?