Updating/adding unbounded XML in Java/JAXB












0















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>


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.



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?



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>









share|improve this question





























    0















    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>


    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.



    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?



    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>









    share|improve this question



























      0












      0








      0








      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>


      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.



      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?



      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>









      share|improve this question
















      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>


      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.



      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?



      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>






      java xml jaxb






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 20 at 4:00







      jackt1997

















      asked Jan 20 at 3:51









      jackt1997jackt1997

      283




      283
























          1 Answer
          1






          active

          oldest

          votes


















          0














          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>


          For details and examples of XSD sequences, see this W3C page.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54273426%2fupdating-adding-unbounded-xml-in-java-jaxb%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            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>


            For details and examples of XSD sequences, see this W3C page.






            share|improve this answer




























              0














              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>


              For details and examples of XSD sequences, see this W3C page.






              share|improve this answer


























                0












                0








                0







                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>


                For details and examples of XSD sequences, see this W3C page.






                share|improve this answer













                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>


                For details and examples of XSD sequences, see this W3C page.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 20 at 4:41









                entpnerdentpnerd

                5,00722044




                5,00722044






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54273426%2fupdating-adding-unbounded-xml-in-java-jaxb%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Liquibase includeAll doesn't find base path

                    How to use setInterval in EJS file?

                    Petrus Granier-Deferre