有什么方法可以在运行时决定我想将 XML 解组到哪个 java 类中?
我尝试以这种方式解组代码 -
public Object unmarshallXml(String xmlReq, String className)
{
String myClass = className+".class";
Object instances = null;
try {
JAXBContext jc = JAXBContext.newInstance( myClass );
Unmarshaller u = jc.createUnmarshaller();
StringBuffer xmlStr = new StringBuffer( xmlReq );
StringReader strReader = new StringReader( xmlStr.toString() );
StreamSource strSource = new StreamSource(strReader);
Object o = u.unmarshal( strSource );
} catch (JAXBException e) {
e.printStackTrace();
}
return instances;
}
但得到这个错误 -
" javax.xml.bind.JAXBException: "LookupInstances.class" doesnt contain ObjectFactory.class or jaxb.index"