XSD Best Practice

N

Nick

I'm looking for any guidelines along the lines of XSD Best practices
for the following issues.

If you are modelling something like interest rates, there is a choice
of how you represent that interest rate. For example you could
represent an interest rate of 5.125% as "5.125", or you could represent
the rate as "0.05125".

Somewhere you need to have some information about what 'style' is being
used

One option is an attribute

<InterestRate representation="percentage">5.125</InterestRate>

or

<InterestRate representation="decimal">0.05125</InterestRate>

However this does give flexibility, but it does mean you have to
represent the style every time it is used.

I see that the alternative is to restrict to one choice, and move that
the schema as a comment.

Another option is to put out both choices all the time. Perhaps as
attributes.

<InterestRate decimal="0.05125" percentage="5.125"/>

Then there are the question of what I call domain values. For example,
there is an ISO standard for currencies. It is a three letter code. USD
for US dollars. GBP for pounds sterling,...

Here, you would want to make the codes a separate type, probably with a
pattern restriction and a comment about the representation being used.

Any comments in general about approaches to take to this part of schema
modelling?

Nick
 
J

Joe Kesselman

Your question seems to be basic data representation best-practice.

Unless human-readability is your primary goal, I would suggest you use a
value that can be parsed directly rather than having to be recalculated
before use (hence 0.05125 is probably preferable).

Monetary values will probably need to be tagged with currency, unless
you're going to standardize on one as the official price and calculate
the others based on current exchange rates.

In other words, it's essentially the same questions as in any other data
file.
 
A

Andy Dingley

Nick said:
If you are modelling something like interest rates, there is a choice
of how you represent that interest rate. For example you could
represent an interest rate of 5.125% as "5.125", or you could represent
the rate as "0.05125".

Percentages are evil. They shouldn't be, but long experience suggests
that they keep causing errors. Use ratios.
 
N

Nick

There is the trade off. Humans on the whole prefer percentages (it is
domain specific) and that aids the readability.

However if you look at a lot of financial apps, then the decimal makes
a lot more sense, particularly as this would
be the preferred internal representation. ie. No maths to convert on
the way out.

On schema design, personally I don't like attributes. However for meta
data, I think they do make sense. So here
putting the type of representation out as a attribute makes sense.

There is still the option of having multiple coupons and using an
attribute / element to say what the representation is.

<interest_rate>
<decimal>0.05125</decimal>
<percentage>5.125</percentage>
</interest_rate>

or

<interest_rate>
<rate representation="decimal">0.05125</rate>
<rate representation="percentage">5.125</rate>
</interest_rate>

Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,838
Latest member
KandiceChi

Latest Threads

Top