【问题标题】:Scala XML from Node to String warnings从节点到字符串的 Scala XML 警告
【发布时间】:2018-10-12 13:26:17
【问题描述】:

我的问题是关于scala.xml 以及从Node 类型到String 的转换(使用任何buildStringtoString 方法)。

当我将这种转换为标准输出时,我会收到有关输入的警告列表,如下所示:

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,但我没有收到任何警告。

为了解析,我使用了一个自定义对象,它从 scala.xml 扩展了 XMLLooader,并带有 SAXParsersetValidation(false)。然后我就使用loadString(input) 来获取我的节点。

查看SAXParser 的文档,我在这里结束:https://docs.oracle.com/javase/7/docs/api/org/xml/sax/helpers/DefaultHandler.html#warning(org.xml.sax.SAXParseException) 上面写着,在默认情况下没有为警告提供任何操作。

【问题讨论】:

  • 您能否详细解释一下您的应用程序的设置并添加一些代码(例如您的自定义对象扩展 XMLLoader)?您是否从外部源加载 html/xml,并且您是否识别所提到的属性? (如“myAttribute1”)
  • 经过一番调查,我发现西蒙的答案已经解决了。应用程序进行了整理。

标签: xml scala logging warnings stdout


【解决方案1】:

看起来您的输出来自 this question about removing warnings 中所述的 JTidy,或者可能来自其他一些“整洁”的库。

当我尝试你的线路时:

data.buildString(true).getBytes(StandardCharsets.UTF_8)

它没有给我任何你得到的输出,也许是程序的另一部分导致了这个?

【讨论】:

  • 我已经看到了 JTydy 的那篇文章,但是一旦我不使用它,我不知道在哪里设置这些属性。如果有帮助的话,我用更多关于解析的信息编辑了这个问题。如果你能指出我在哪里/什么更改为scala.xmlSAXParser 这些属性,我会试一试。
  • 我发现某个地方很整洁。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-23
  • 2020-09-23
  • 1970-01-01
  • 2011-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多