Я пытаюсь распаковать файл XML, но продолжаю получать эту ошибку:
javax.xml.bind.UnmarshalException: unexpected element (uri:"MyProtocol.xsd", local:"MyFrame"). Expected elements are (none)
Я использую Axis2 для создания классов с привязкой ADB из моего файла wsdl. Это корень .wsdl:
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:xs="http://www.w3.org/2001/XMLSchema/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="MyProtocol.xsd"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:wsi="http://ws-i.org/profiles/basic/1.1/xsd"
xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="MyProtocol.xsd">
<types>
<xs:schema targetNamespace="MyProtocol.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="MyProtocol.xsd"
elementFormDefault="qualified">
<xs:import namespace="http://ws-i.org/profiles/basic/1.1/xsd"
schemaLocation="http://ws-i.org/profiles/basic/1.1/swaref.xsd" />
<xs:element name="MyFrame">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
...
Это код, который я должен распаковать, и я предполагаю, что он не работает с привязками Axis2 и ADB.
public class Foobar<T>
{
private T obj;
private Class<T> type;
public Foobar(Class<T> type) {
this.type = type;
}
public void unmarshalXML(String xml) {
JAXBContext jaxbContext;
Unmarshaller unmarshaller;
StringReader reader;
try {
jaxbContext = JAXBContext.newInstance(type);
unmarshaller = jaxbContext.createUnmarshaller();
reader = new StringReader(xml);
obj = (T) unmarshaller.unmarshal(reader);
} catch(JAXBException e) {
e.printStackTrace();
}
}
}
Axis2 генерирует класс-заглушку, в котором есть все геттеры, сеттеры и классы из вариантов моей схемы. Я использую этот класс и вызываю метод unmarshal
следующим образом:
Foobar<MyStub.MyFrame> foobar = new Foobar<MyStub.MyFrame>(MyStub.MyFrame.class);
// Unmarshal
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<MyFrame xmlns=\"MyProtocol.xsd\">"
+ "<YC>"
+ "<SenderId>172</SenderId>"
+ "<RequestId>123saA</RequestId>"
+ "<SubNumber>5558879876</SubNumber>"
+ "</YC>"
+ "</MyFrame>";
foobar.unmarshalXML(xml);
Затем я получаю сообщение об ошибке выше. Почему это происходит? Мой код неправильный?