首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带命名空间的Soap xml到对象jaxb

带命名空间的Soap xml到对象jaxb
EN

Stack Overflow用户
提问于 2015-06-25 20:16:00
回答 1查看 1K关注 0票数 0

我是xml编组-解组的新手,我正在尝试将以下带命名空间的SOAP Xml转换为JAVA对象。

代码语言:javascript
复制
  <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的相应类包括

代码语言:javascript
复制
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解析成object。我在这里使用的是JAXB。谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-06-25 21:24:33

This链接上找到上述问题的答案

并且问题似乎已经被回答了here

谢谢

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31050134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档