JAXB,要解组的 POJO 中每个元素有一个以上的命名空间 XML

JAXB, more than one namespace per element in POJOs to unmarshal XML

如何接受 namesspacesunmarshal 的不同版本?我有许多使用 JAXB 生成的 classes。我想解组以从 XML 中获取信息。问题是 xml 有不同的 xmlns 版本。

我将举一个简单的例子,因为我的 classes 太长了。

拥有 class:

@XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = { "attribute1"})
    @XmlRootElement(name = "myClass", namespace = "http://www.test.com/xml-schema/MYC/1.0")
    public class myClass {

        @XmlElement(name = "attribute_1", namespace = "http://www.test.com/xml-schema/MYC/1.0", required = true)
        protected String attribute1;

        @XmlElement(name = "attribute_2", namespace = "http://www.test.com/xml-schema/MYC/1.0")
        protected String attribute2;
    }

我不仅要接受 XML 还要接受 xmlns 这样的:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Reha xmlns="http://www.test.com/xml-schema/MYC/1.0"

但也 xmlns 喜欢:

http://www.test.com/xml-schema/MYC/1.2
http://www.test.com/xml-schema/MYC/1.5
http://www.test.com/xml-schema/MYC/1.8
http://www.test.com/xml-schema/MYC/2.9

考虑到我还有其他 classes 与其他名称空间,具有相同的问题(名称空间中的不同版本)

我看过不同的帖子,但我不是很清楚。我怎样才能做到这一点?

在对用户案例进行更深入的思考和理解之后。

如果一个模式有不同的版本,这意味着XML的结构发生了变化,这意味着我们将需要两个不同的类来表示两个不同的命名空间版本,例如对于两个不同的命名空间:

http://www.test.com/xml-schema/MYC/1.2
http://www.test.com/xml-schema/MYC/1.5