Updating/adding 无限 XML 在 Java/JAXB
Updating/adding unbounded XML in Java/JAXB
所以我将 XML 编组和解组到一个列表中,我有一些用户帐户,其中包含用户名、当前资金等,但单个用户可以拥有一个或多个股份。
<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 value
.
他们是否是格式化 XML 的更好方法,这样我就可以将新的 strings/floats 插入、添加和更新到帐户 XML?
如果有帮助,我希望我的 XML 看起来像这样 -
<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>
将以下内容添加到您的 Account
XSD 架构中以正确添加 Shares
:
<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 序列的详细信息和示例,请参阅 this W3C page。
所以我将 XML 编组和解组到一个列表中,我有一些用户帐户,其中包含用户名、当前资金等,但单个用户可以拥有一个或多个股份。
<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 value
.
他们是否是格式化 XML 的更好方法,这样我就可以将新的 strings/floats 插入、添加和更新到帐户 XML?
如果有帮助,我希望我的 XML 看起来像这样 -
<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>
将以下内容添加到您的 Account
XSD 架构中以正确添加 Shares
:
<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 序列的详细信息和示例,请参阅 this W3C page。