java Uri 不是绝对的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12288390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uri is not absolute
提问by Acdc RocknRoll
I am trying to unmarshall the following xml file with the method Jaxb.unmarshall(String,Class)
. I always get the error:
我正在尝试使用方法解组以下 xml 文件Jaxb.unmarshall(String,Class)
。我总是收到错误:
Exception in thread "main" java.lang.IllegalArgumentException: URI is not absolute:
Exception in thread "main" java.lang.IllegalArgumentException: URI is not absolute:
XML file:
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>
采纳答案by Jér?me Radix
Here is a working Java unmarshalling examplefrom your xml example.
这是您的 xml 示例中的一个有效的 Java 解组示例。
You have a root element called spieltag and an inner element that also called spieltag. That may cause problems if you have not well defined this in your XMLSchema. In the example, I've used spieltag2
for the inner spieltag
element.
您有一个名为 spieltag 的根元素和一个也称为 spieltag 的内部元素。如果您没有在 XMLSchema 中很好地定义它,这可能会导致问题。在示例中,我使用spieltag2
了内部spieltag
元素。
Also, don't forget to compile package-info.java with the proper @XmlSchema
:
另外,不要忘记使用正确的编译 package-info.java @XmlSchema
:
As said here, You can use the @XmlSchema
annotation on a package-info
class to control the namespace qualification. If you have already written a package-info class make sure it is being compiled (some versions of ant had problems with package-info classes).
正如这里所说,您可以使用类@XmlSchema
上的注释package-info
来控制命名空间限定。如果您已经编写了一个 package-info 类,请确保它正在被编译(某些版本的 ant 有 package-info 类的问题)。
package-info
包信息
@XmlSchema(
namespace = "http://arnezelasko.de/spieltag",
elementFormDefault = XmlNsForm.QUALIFIED)
package de.arnezelasko.spieltag;
For More Information
想要查询更多的信息