XML SOAP信封在JAXB中为空

我正试图用JAXB解组XML以将其转换为对象,但是SOAPPArt,SOAPEnvelope和SOAPBody都为null,我不知道为什么。

我也尝试在没有SOAPMessage的情况下进行封送,但是没有成功。

这是我要解组的XML:

<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>
        <ObjectXmlResponse
            xmlns="http://tempuri.org/testing">
            <ResultadoXml xmlns="www.site.com.br">
                <CodigoOperacao>dsadsdas</CodigoOperacao>
                <OperacoesObjetoAnalise />
                <Respostas>
                    <Resposta Final="true">
                        <Sistema>dsadfd</Sistema>
                        <Criterio>fdsfdsf</Criterio>
                        <Resposta>.</Resposta>
                    </Resposta>
                </Respostas>
            </ResultadoXml>
        </ObjectXmlResponse>
    </soap:Body>
</soap:Envelope> 

以下是课程:

@XmlRootElement(name="ObjectXmlResponse",namespace="http://tempuri.org/testing")
@XmlaccessorType(XmlaccessType.FIELD)
public class ObjectXmlResponse {    

    @XmlElement(name="ResultadoXml",namespace="www.site.com.br")
    private ResultadoXml resultadoXml;

    public ResultadoXml getResultadoXml() {
        return resultadoXml;
    }

    public void setResultadoXml(ResultadoXml resultadoXml) {
        this.resultadoXml = resultadoXml;
    }

}
@XmlRootElement(name="ResultadoXml",namespace="www.site.com.br")
@XmlaccessorType(XmlaccessType.FIELD)
public class ResultadoXml {

    private static final long serialVersionUID = 1L;

    @XmlElement(name="CodigoOperacao")
    private String codigoOperacao;

    @XmlElement(name="OperacoesObjetoAnalise")
    private String OperacoesObjetoAnalise;  

    @XmlElement(name="Respostas")
    private Respostas respostas;

    @XmlElement(name="Drivers")
    private Drivers drivers;

    public String getcodigoOperacao() {
        return codigoOperacao;
    }

    public void setCodigoOperacao(String codigoOperacao) {
        this.codigoOperacao = codigoOperacao;
    }

    public Respostas getRespostas() {
        return respostas;
    }

    public void setRespostas(Respostas respostas) {
        this.respostas = respostas;
    }

    public Drivers getDrivers() {
        return drivers;
    }

    public void setDrivers(Drivers drivers) {
        this.drivers = drivers;
    }   

    public String getOperacoesObjetoAnalise() {
        return OperacoesObjetoAnalise;
    }

    public void setOperacoesObjetoAnalise(String operacoesObjetoAnalise) {
        OperacoesObjetoAnalise = operacoesObjetoAnalise;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

    public String toString(){
        return "ResultadoXml [codigoOperacao=" + codigoOperacao +"]";
    }

}

这是元帅:

public static void main(String[] args) {        

        JAXBContext jaxbContext;        

        try {

            String relatorio = <the xml>;

            InputStream is = new ByteArrayInputStream(relatorio.getBytes());

            SOAPMessage message = MessageFactory.newInstance().createMessage(null,is);

            SOAPPart sp = message.getsoAPPart();
            SOAPEnvelope env = sp.getEnvelope();
            SOAPBody bdy = env.getBody();

            jaxbContext = JAXBContext.newInstance(ObjectXmlResponse.class);

            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

            ObjectXmlResponse response = (ObjectXmlResponse) jaxbUnmarshaller.unmarshal(new StringReader(relatorio));

            System.out.println(response);


        } catch(Exception ex) {
            ex.printStackTrace();
        }   

        system.exit(0);

    }

我需要填充ObjectXmlResponse对象及其属性,例如ResultadoXml。

a13406120179 回答:XML SOAP信封在JAXB中为空

在所有元素上指定名称空间(或在包上使用@XmlSchema),并使用以下内容解组SOAP正文内容

ObjectXmlResponse response = (ObjectXmlResponse) jaxbUnmarshaller.unmarshal(bdy.extractContentAsDocument());
本文链接:https://www.f2er.com/3137477.html

大家都在问