我正在尝试使用方法 Jaxb.unmarshall(String,Class)
解码以下 xml 文件。我总是收到错误:
线程“main”中的异常 java.lang.IllegalArgumentException:URI 不是绝对的:
XML 文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<spieltag xmlns="http://arnezelasko.de/spieltag">
<game>
<spieltag>28</spieltag>
<nummer>1</nummer>
<beginn>2010-03-26 20:30:00</beginn>
<mannschaft_heim><![CDATA[VfL Bochum]]></mannschaft_heim>
<mannschaft_gast><![CDATA[Eintracht Frankfurt]]></mannschaft_gast>
<tore_heim_halbzeit>1</tore_heim_halbzeit>
<tore_gast_halbzeit>1</tore_gast_halbzeit>
<tore_heim_ergebnis>1</tore_heim_ergebnis>
<tore_gast_ergebnis>2</tore_gast_ergebnis>
</game>
<game>
<spieltag>28</spieltag>
<nummer>2</nummer>
<beginn>2010-03-27 15:30:00</beginn>
<mannschaft_heim><![CDATA[Bayern München]]></mannschaft_heim>
<mannschaft_gast><![CDATA[VfB Stuttgart]]></mannschaft_gast>
<tore_heim_halbzeit></tore_heim_halbzeit>
<tore_gast_halbzeit></tore_gast_halbzeit>
<tore_heim_ergebnis></tore_heim_ergebnis>
<tore_gast_ergebnis></tore_gast_ergebnis>
</game>
最佳答案
这是一个working Java unmarshalling example来自您的 xml 示例。
您有一个名为 spieltag 的根元素和一个也称为 spieltag 的内部元素。如果您没有在 XMLSchema 中很好地定义这一点,则可能会导致问题。在示例中,我使用了 spieltag2
作为内部 spieltag
元素。
另外,不要忘记使用正确的 @XmlSchema
编译 package-info.java :
如前所述here ,您可以在 package-info
类上使用 @XmlSchema
注释来控制命名空间限定。如果您已经编写了 package-info 类,请确保正在编译它(某些版本的 ant 在 package-info 类方面存在问题)。
包信息
@XmlSchema(
namespace = "http://arnezelasko.de/spieltag",
elementFormDefault = XmlNsForm.QUALIFIED)
package de.arnezelasko.spieltag;
了解更多信息
关于java - Uri 不是绝对的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12288390/