1
我已生成使用JAXB從這個XSD文件javax.xml.bind.UnmarshalException:
<xs:schema xmlns:tns="http://testwork/"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://testwork/">
<xs:element name="sayHelloWorldFrom" type="tns:sayHelloWorldFrom"/>
<xs:element name="sayHelloWorldFromResponse" type="tns:sayHelloWorldFromResponse"/>
<xs:complexType name="sayHelloWorldFrom">
<xs:sequence>
<xs:element name="arg0" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHelloWorldFromResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
歸類這是生成的類
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sayHelloWorldFrom", namespace = "http://testwork/", propOrder = {
"arg0"
})
public class SayHelloWorldFrom {
protected String arg0;
/**
* Gets the value of the arg0 property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getArg0() {
return arg0;
}
/**
* Sets the value of the arg0 property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setArg0(String value) {
this.arg0 = value;
}
}
我一樣有這樣
SOAP消息<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tes="http://testwork/">
<soapenv:Header/>
<soapenv:Body>
<tes:sayHelloWorldFrom>
<!--Optional:-->
<arg0>?</arg0>
</tes:sayHelloWorldFrom>
</soapenv:Body>
</soapenv:Envelope>
我想將此消息格式化爲類SayHelloWorldFrom,這裏是我的代碼示例
public void unmarshalSoapRequest(InputStream is) throws JAXBException {
JAXBContext js = JAXBContext.newInstance(SayHelloWorldFrom.class);
Unmarshaller unmarshaller = js.createUnmarshaller();
SayHelloWorldFrom sayHelloWorldFrom = (SayHelloWorldFrom) unmarshaller.unmarshal(is);
但是我有一個像
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope"
). Expected elements are (none)
我在做什麼錯在Tomcat中記錄一個錯誤?請幫助新手:-) Thann in advnance
以下內容將有所幫助:http://blog.bdoughan.com/2012/08/handle-middle-of-xml-document-with-jaxb.html –