gpt4 book ai didi

java - JAXB : Read non-static attributes into a collection

转载 作者:太空宇宙 更新时间:2023-11-04 11:17:26 25 4
gpt4 key购买 nike

我想编写一个 JAXB 实现来读取/解码以下 XML。这里的挑战是如何读取名称未定义的属性。在下面的示例中,按键可以从 A1 到 AN 变化。我的问题是,我们这里可以使用JAXB吗?如果是,如何编写Node.java类?

<?xml version="1.0"?>

<Node A1="blabla"
A2="xyz"
A3="APPLICATION"
A4="dfd"
A5="dfd"
...
>
</Node>


public class Node {
//What is to be done here?

}

最佳答案

您可以使用@XmlAnyAttribute:

@XmlRootElement
public class Node {

@XmlAnyAttribute
private Map<QName,String> attributeMap;

//getters and setters

}

来源:https://docs.oracle.com/javase/7/docs/api/javax/xml/bind/annotation/XmlAnyAttribute.html

关于java - JAXB : Read non-static attributes into a collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45302075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com