Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带命名空间的Soap xml到对象jaxb_Java_Xml_Soap_Jaxb - Fatal编程技术网

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

Java 带命名空间的Soap xml到对象jaxb,java,xml,soap,jaxb,Java,Xml,Soap,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/>

我是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>

java是一种编程语言
101
拉维
java是一个平台
102
厕所
什么是java?
sdfsdfs
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;
    }

}
公共类答案{
私有int-id;
私有字符串应答器名称;
私人字符串postedby;
公众答覆({
}
公共应答(int-id、字符串应答器名称、字符串postedby){
超级();
this.id=id;
this.answername=answername;
this.postedby=postedby;
}
公共int getId(){
返回id;
}
公共无效集合id(内部id){
this.id=id;
}
公共字符串getAnswername(){
返回应答器名称;
}
public void setAnswername(字符串answername){
this.answername=answername;
}
公共字符串getPostedby(){
回信人;
}
公共void setPostedby(字符串postedby){
this.postedby=postedby;
}
}
导入javax.xml.bind.annotation.XmlAttribute;
导入javax.xml.bind.annotation.xmlement;
导入javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
公开课问题{
私有int-id;
私有字符串名称;
私人名单答案;
公众问题({
}
公共问题(int-id、字符串问题名、列表答案){
超级();
this.id=id;
this.questionname=questionname;
这个。答案=答案;
}
@XmlAttribute
公共int getId(){
返回id;
}
公共无效集合id(内部id){
this.id=id;
}
@XmlElement
公共字符串getQuestionname(){
返回问题名称;
}
public void setQuestionname(字符串questionname){
this.questionname=questionname;
}
@XmlElement
公共列表getAnswers(){
返回答案;
}
公共答案(列出答案){
这个。答案=答案;
}
}
此xml包含SoapBody和SoapEnvelope。任何人都可以建议在java类中进行哪些更改,以将此xml转换为对象形式。 如何将xml解析为对象。我在这里使用JAXB。
谢谢

在链接上找到了上述问题的答案

这个问题似乎已经得到了回答

多谢各位