Issue with namespaces in XMLs in JAXB unmarshalling

≯℡__Kan透↙ 提交于 2019-12-02 03:58:47

XMLAtribute has atribute namesape, so

@XmlAttribute(name = "Id", namespace="http://schemas.microsoft.com/2003/10/Serialization").

While judging by your xml, the cat is in the same namespace as the animal so

The following code works with JDK 7 (fixed the ns for animal and attribute name for zid).

@XmlRootElement(name = "Animal",namespace = "http://allmycats.com/serviceplatform/1.0/")
public class Animal2{
    List<Cat2> cats;

    @XmlElement(name = "Cat")
    public List<Cat2> getCats() {
        return cats;
    }

    public void setCats(List<Cat2>cats) {
        this.cats= cats;
    }
}
@XmlRootElement(name = "Cat")
public class Cat2 {
    private String zId;

    @XmlAttribute(name = "Id", namespace="http://schemas.microsoft.com/2003/10/Serialization/")
    public String getzId() {
        return zId;
    }
    public void setzId(String zId) {
        this.zId = zId;
    }

    private String name;

    @XmlElement(name = "name")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!