在Java / JAXB中更新/添加无界XML [英] Updating/adding unbounded XML in Java/JAXB
问题描述
所以我将XML编组并解组到List中,我有一些用户帐户包含用户名,当前资金等,但是单个用户可以拥有一个或多个共享。
So I'm marshalling and unmarshalling XML into a List, I've got some user accounts which contain a username, current funds etc but a single user can own one or many shares.
<xsd:complexType name="Accounts">
<xsd:sequence>
<xsd:element name="Username" type="xsd:string"/>
<xsd:element name="Password" type="xsd:string"/>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="Funds" type="xsd:float"/>
<xsd:element name="ownedShares">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Symbol" maxOccurs="unbounded" type="xsd:string" />
<xsd:element name="Amount" type="xsd:int" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
我的问题是我不知道如何添加到他们拥有的股票,我可以添加新用户并更新现有的,但更新自有股份的函数参数是 Accounts.OwnedShares值
。
My problem is I don't know how to add to their owned shares, I can add new users and update existing ones, but the function parameter to update owned shares is a Accounts.OwnedShares value
.
是他们的格式化XML的更好方法是什么我可以插入并添加和更新新的字符串/浮点数到帐户XML中?
Is their a better way to format the XML so I can just insert and add and update new strings/floats into the accounts XML?
如果有帮助我希望我的XML看起来像像这样 -
If it helps I want my XML to look a little like this -
<Username>Test</Username>
<Password>Test</Password>
<Name>Test</Name>
<Funds>111</Funds>
<Shares>
<Company>Test</Company>
<Amount>111</Amount>
</Shares>
<Shares>
<Company>test2</Company>
<Amount>10</Amount>
</Shares>
</Account>
推荐答案
将以下内容添加到帐户
XSD架构要正确添加股票
:
Add the following to your Account
XSD schema to have Shares
added correctly:
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="Shares">
<xs:complexType>
<xs:sequence>
<xs:element name="Company" type="xs:string"/>
<xs:element name="Amount" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
有关XSD序列的详细信息和示例,请参阅这个W3C页面。
For details and examples of XSD sequences, see this W3C page.
这篇关于在Java / JAXB中更新/添加无界XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!