I am looking for a XSD to validate if a XML containing file elements with many payments have the same currency.
Example:
<Payments>
<Payment>
<PaymentDate>2020-09-28</PaymentDate>
<Amount>11</Amount>
<Currency>USD</Currency>
</Payment>
<Payment>
<PaymentDate>2020-09-27</PaymentDate>
<Amount>19</Amount>
<Currency>USD</Currency>
</Payment>
<Payment>
<PaymentDate>2020-09-27</PaymentDate>
<Amount>12</Amount>
<Currency>USD</Currency>
</Payment>
</Payments>
The upper XML should be considered as valid because all <Currency>
elements contain the same currency information.
However, the following XML should not be valid as it contains at least one payment with different currency information:
<Payments>
<Payment>
<PaymentDate>2020-09-28</PaymentDate>
<Amount>11</Amount>
<Currency>USD</Currency>
</Payment>
<Payment>
<PaymentDate>2020-09-27</PaymentDate>
<Amount>19</Amount>
<Currency>EUR</Currency>
</Payment>
<Payment>
<PaymentDate>2020-09-27</PaymentDate>
<Amount>12</Amount>
<Currency>USD</Currency>
</Payment>
</Payments>
What should I do for my XSD? Thanks!
This needs XSD 1.1 with assertions:
I don't think there's any way to do it with XSD 1.0.