Hi I'm trying parse xml with jaxb but its body always return null. I tried to create object of that class and convert it to xml that is same fine result but when try to parse it that is not working.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<St_PurchaseResponse xmlns="http://tempuri.org/">
<St_PurchaseResult>
<string>RESULT STRING</string>
</St_PurchaseResult>
</St_PurchaseResponse>
</soap:Body>
</soap:Envelope>
with following code:
val responseObj: PurchaseResponseEnvelope? =
JAXBContext.newInstance(PurchaseResponseEnvelope::class.java).createUnmarshaller()
.unmarshal(StreamSource(StringReader(response)), PurchaseResponseEnvelope::class.java).value
@XmlRootElement(name = "soap:Envelope")
@XmlAccessorType(XmlAccessType.FIELD)
open class ApiEnvelope {
@XmlAttribute(name = "xmlns:soap")
val soapAttr = "http://schemas.xmlsoap.org/soap/envelope/"
@XmlAttribute(name = "xmlns:xsi")
val xsiAttr = "http://www.w3.org/2001/XMLSchema-instance"
@XmlAttribute(name = "xmlns:xsd")
val xsdAttr = "http://www.w3.org/2001/XMLSchema"
constructor()
}
@XmlRootElement(name = "soap:Envelope")
@XmlAccessorType(XmlAccessType.FIELD)
class PurchaseResponseEnvelope : ApiEnvelope {
@XmlElement(name = "soap:Body")
var body: PurchaseResponseBody? = null
constructor(body: PurchaseResponseBody) {
this.body = body
}
constructor() : super()
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
class PurchaseResponseBody {
@XmlElement(name = "St_PurchaseResponse")
var body: PurchaseResponseBodyWrap? = null
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
class PurchaseResponseBodyWrap {
@XmlAttribute(name = "xmlns")
val namespace = "http://tempuri.org/"
@XmlElement(name = "St_PurchaseResult")
var result: PurchaseResponseResult? = null
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
class PurchaseResponseResult {
@XmlElement(name = "string")
var result: String? = null
}
But this is not working body always null i tried to marshall object that is fine same xml result but when unmarshall always null body