当我尝试读取包含一些日语字符的 XML 文件时,出现以下错误。
javax.xml.bind.PropertyException: jaxb.encoding
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.getProperty(AbstractUnmarshallerImpl.java:360)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.getProperty(UnmarshallerImpl.java:423)
at com.jaxb.JAXBTest.main(JAXBTest.java:23)
enter code here
包com.jaxb;
import java.io.FileReader;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
public class JAXBTest
{
public static void main(String args[])
{
try
{
JAXBContext context = JAXBContext.newInstance(com.pain.jaxb.ver2.Document.class);
Unmarshaller um = context.createUnmarshaller();
um.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
com.pain.jaxb.ver2.Document PainTransferList2 = (com.pain.jaxb.ver2.Document) um.unmarshal(new FileReader("C:/WorkArea/JAXB/src/com/pain/messages/APXSEPAS_510812_1.XML"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
请指教。
谢谢
拉菲
您正在设置一个Marshaller
财产在Umarshaller
:
Unmarshaller um = context.createUnmarshaller();
um.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
你只能设置Unmarshaller
上的属性Unmarshaller
.
去除setProperty
然后再试一次。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)