在 Java/JAXB 中更新/添加无界 XML

因此,我将 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 的更好方法,因此我可以将新字符串/浮点数插入、添加和更新到帐户 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>


MM们
浏览 108回答 1
1回答

慕码人8056858

将以下内容添加到您的AccountXSD 架构中以Shares正确添加:<xs:sequence minOccurs="0" maxOccurs="unbounded">&nbsp; <xs:element name="Shares">&nbsp; &nbsp; <xs:complexType>&nbsp; &nbsp; &nbsp; <xs:sequence>&nbsp; &nbsp; &nbsp; &nbsp; <xs:element name="Company" type="xs:string"/>&nbsp; &nbsp; &nbsp; &nbsp; <xs:element name="Amount" type="xs:string"/>&nbsp; &nbsp; &nbsp; </xs:sequence>&nbsp; &nbsp; </xs:complexType>&nbsp; </xs:element></xs:sequence>有关 XSD 序列的详细信息和示例。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java