【问题标题】:XML to JAXB binding having nested elements?具有嵌套元素的 XML 到 JAXB 绑定?
【发布时间】:2014-12-31 06:55:51
【问题描述】:

我有以下 XML。

               <elementAttributes>
                        <elementAttribute>
                            <attributeName>BIFM Service</attributeName>
                            <attributeValues>
                                <attributeValue>AssetCollector</attributeValue>
                            </attributeValues>
                        </elementAttribute>
                        <elementAttribute>
                            <attributeName>Search Service</attributeName>
                            <attributeValues>
                                <attributeValue>BudgetEstimator</attributeValue>
                            </attributeValues>
                        </elementAttribute>
                        <elementAttribute>
                            <attributeName>AgendizeExternal Service</attributeName>
                            <attributeValues>
                                <attributeValue>agendizeExternal</attributeValue>
                            </attributeValues>
                        </elementAttribute>
                    </elementAttributes>

现在 JAXB 类应该具有哪些属性/字段?

【问题讨论】:

    标签: java xml web-services jaxb


    【解决方案1】:

    试试这个

    public class Test { 
    
        static class Element {
            @XmlElement
            String attributeName;
            @XmlElement
            @XmlElementWrapper(name="attributeValues")
            List<String> attributeValue;
        }
    
        @XmlElement
        List<Element> elementAttribute;
    
        public static void main(String[] args) throws Exception {
            Test t = JAXB.unmarshal(new File("1.xml"), Test.class);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-11
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多