XSD element data duplication

93 views Asked by At

I have an XSD and XML files that works 90% and is almost completed. For example, if I have this XML document.

<Family>
    <Family_Client>
        <ClientID>1234</ClientID>
    </Family_Client>
    <Loan>
        <Family_Client>
            <ClientID>1234</ClientID>
        </Family_Client>
    </Loan>
</Family>

Is it possible to manipulate the XSD (XML Schema) to make sure that the ClientID in loan is the same as the clientID above in Family_Client?

Also, if there are multiple Family_Clients, I want the Family_Client in Loan to also be the same. So example of this would be:

<Family>
    <Family_Client>
        <ClientID>1234</ClientID>
    </Family_Client>
    <Family_Client>
        <ClientID>2345</ClientID>
    </Family_Client>
    <Loan>
        <Family_Client>
            <ClientID>1234</ClientID>
        </Family_Client>
        <Family_Client>
            <ClientID>2345</ClientID>
        </Family_Client>
    </Loan>
</Family>
1

There are 1 answers

3
Dijkgraaf On

I would recommend changing the structure of your schema.

If each loan only belongs to a single family client then you should put it under that node. If you want to have multiple loans per client, put them under a Loans node

<Family>
    <Family_Client>
        <ClientID>1234</ClientID>
        <Loans>
            <Loan>
                   <!-- details of loan here -->
            </Loan>    
            <Loan>
                   <!-- details of loan here -->
            </Loan>    
        </Loans>
    </Family_Client>
</Family>