簡體   English   中英

具有名稱空間的SOAP XML對象jaxb

[英]Soap xml with namespace to object jaxb

我是xml封送處理的新手-拆封處理,我正在嘗試將以下具有名稱空間的SOAP Xml轉換為JAVA對象。

  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://example.com/test/V1" xmlns:v11="http://example.com/test//Core/V1/">
       <soapenv:Header/>
       <soapenv:Body>
         <question id="1">  
        <v1:answers>  
            <v11:answername>java is a programming language</v11:answername>  
            <v11:id>101</v11:id>  
            <v11:postedby>ravi</v11:postedby>  
        </v1:answers>  
        <v1:answers>  
            <v11:answername>java is a platform</v11:answername>  
            <v11:id>102</v11:id>  
            <v11:postedby>john</v11:postedby>  
        </v1:answers>  
        <v1:questionname>What is java?</v1:questionname>  
        <v1:questionnamedd>sdfsdfs</v1:questionnamedd>  
 </question>
  </soapenv:Body>
</soapenv:Envelope>

xml的相應類是

public class Answer {
    private int id;
    private String answername;
    private String postedby;

    public Answer() {
    }

    public Answer(int id, String answername, String postedby) {
        super();
        this.id = id;
        this.answername = answername;
        this.postedby = postedby;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getAnswername() {
        return answername;
    }

    public void setAnswername(String answername) {
        this.answername = answername;
    }

    public String getPostedby() {
        return postedby;
    }

    public void setPostedby(String postedby) {
        this.postedby = postedby;
    }

}

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Question {
    private int id;
    private String questionname;
    private List<Answer> answers;

    public Question() {
    }

    public Question(int id, String questionname, List<Answer> answers) {
        super();
        this.id = id;
        this.questionname = questionname;
        this.answers = answers;
    }

    @XmlAttribute
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @XmlElement
    public String getQuestionname() {
        return questionname;
    }

    public void setQuestionname(String questionname) {
        this.questionname = questionname;
    }

    @XmlElement
    public List<Answer> getAnswers() {
        return answers;
    }

    public void setAnswers(List<Answer> answers) {
        this.answers = answers;
    }

}

此xml包含SoapBody和SoapEnvelope。 任何人都可以建議在Java類中進行更改以使該xml成為對象形式。 如何將xml解析為對象。 我在這里使用JAXB。 謝謝

鏈接上找到了上述問題的答案

似乎問題已經在這里回答

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM