解组 JAVA Web 服务中的嵌套或复杂数据元素 [英] Unmarshalling nested or complex data elements in JAVA Web services

查看:24
本文介绍了解组 JAVA Web 服务中的嵌套或复杂数据元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发 JAVA 网络服务,并提出了网络服务的意见.输入有数据元素,最后一个元素是一个 Arraylist,它有四个项目.我们能够获取不在 arraylist 中的第一组元素的值,然后将它们保存或存储在数据库中.我们面临的挑战是获取 arraylist 中嵌套元素的值.

We are developing JAVA web services and have come up with input to the web services. The input has data elements and the last element is an Arraylist which has four items. We are able to get the values of first set of elements which are not in arraylist and then save or store them in a database. The challenge we have is to get the values of nested elements in arraylist .

我们正在使用以下代码,但它抱怨或给出无法看到 (DataInfo.xml) XML 文件的错误消息.我们认为这是由 Web 服务输入生成的,但我们看不到它.

We are using the following code but it is complaining or giving error message that it cannot see (DataInfo.xml) XML file. Which we believe is being generated by the web services input but we cannot see it.

JAXBContext jaxbContext = JAXBContext.newInstance(DataInfo.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();          
DataInfo  EXitems = (DataInfo) jaxbUnmarshaller.unmarshal(new File("DataInfo.xml") );

我们如何确保代码(应用程序)可以看到 XML,或者从数组列表或嵌套元素中获取值的最佳方法是什么??

How can we ensure that the XML is seen by the code (application) or what is the best way of getting values from arraylist or nested elements??

我们使用的代码相同

主类

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DataInfo", propOrder = {"firstName","surname", "dateofBirth","studentAddress"})
@XmlRootElement(name = "dataInfo")                                          
public class DataInfo  implements Serializable {

}

ArrayList 类

ArrayList Class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "studentAddress", propOrder = {"address1","address2", "town","country"})
@XmlRootElement(name = "studentAddress")                                            
public class studentAddress  implements Serializable {

}

我在发布时删除了 getter 和 setter 以缩短代码

I have removed getters and setters to shorten the code when posting

请帮忙

推荐答案

这样的事情对我有用,

@XmlElementWrapper(name = "ProfileList")
@XmlElement(name = "Profile")
private List<Profile> listOfProfiles;

对于像这样的 XML 结构,

for an XML structure like,

....
<ProfileList>
    <Profile>......</Profile>
    <Profile>......</Profile>
</ProfileList>
....

这篇关于解组 JAVA Web 服务中的嵌套或复杂数据元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆