当我有以下XML代码时:

<xml>
  <version>1.1</version>
  <url>http://www.google.nl</url>
</xml>

我使用Java代码阅读了此文件,一切正常,但是当XML更改时,例如:
<xml>
  <test>test</test>
  <version>1.1</version>
  <url>http://www.google.nl</url>
</xml>

我收到一个错误,但我希望程序不会停止,并且不要使用现场测试。如果程序没有停止,是否有办法处理此异常?
Exception in thread "main"         com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldExce    ption: No such field Version.iets
---- Debugging information ----
field               : iets
class               : Version
required-type       : Version
converter-type      :     com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /Version/iets
line number         : 1
version             : null
-------------------------------

最佳答案

XStream 1.4.5使您可以轻松处理未知标签。将ignoreUnknownElements用于尚未实现或已被删除且您正在处理旧xml的标记。

http://x-stream.github.io/javadoc/com/thoughtworks/xstream/XStream.html#ignoreUnknownElements%28%29

您还可以指定要忽略的特定标签。

09-10 02:13
查看更多