简体   繁体   English

如何访问另一个xml元素(JAXB bindingsl)中的xml元素

[英]How to access xml element within another xml element (JAXB bindingsl

So I have an xsd schema, there can be a single user with a set of attributes, but this user may have many shares (I'm making a stock brokering app), when a user purchases a share, I unmarshall the XML into a list, I can get and set the users attributes, but I can only get a share object which I cannot set, update, delete. 因此,我有一个xsd模式,可以有一个具有一组属性的用户,但是该用户可能有很多股份(我正在开发股票经纪应用程序),当用户购买股份时,我将XML解组为一个列表中,我可以获取和设置用户属性,但只能获取无法设置,更新,删除的共享对象。

Any ideas? 有任何想法吗?

I assume that your question is related to this one . 我认为你的问题是与此相关的一个

Generating the classes based on your schema you would create an Accounts class. 根据您的架构生成类,您将创建一个Accounts类。

The Accounts class contains a list for which there is no setter. Accounts类包含一个没有设置器的列表。 Check this answer for a detailed explanation on why. 检查此答案以获取有关原因的详细说明。 But still you can do things with this list. 但是您仍然可以使用此列表执行操作。

So when unmarshalling an xml let's say you end up with an Accounts instance and you want to add a new share. 因此,在解组xml时,假设您最终获得一个Accounts实例,并且想要添加一个新共享。 This would look like this: 看起来像这样:

Accounts accounts = unmarshallAccounts();
Accounts.Shares shares = new Accounts.Shares();
shares.setAmount("amount");
shares.setCompany("company");
accounts.getShares().add(shares);

Or did I miss-understood your question? 还是我错过了您的问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM