Solved

What XSD format is this

Posted on 2015-01-15
2
102 Views
Last Modified: 2015-01-16
I have the following type

  <xs:simpleType name="MoneyType">

    <xs:restriction base="xs:string">

      <xs:pattern value="\p{Nd}+(\.\p{Nd}\p{Nd})" />

    </xs:restriction>

  </xs:simpleType>

Open in new window


I use this for numeric fields

When I try to aggregate a large number of fields into a field with this structure, ti fails

Is there a better specification?

Thanks
0
Comment
Question by:Anthony Lucia
2 Comments
 
LVL 23

Accepted Solution

by:
Michael74 earned 250 total points
ID: 40552267
Try this for currency

<xsd:simpleType name="money">
      <xsd:restriction base="xsd:decimal">
         <xsd:fractionDigits value="2"/>
      </xsd:restriction>
</xsd:simpleType>

Open in new window

http://www.java2s.com/Code/XML/XML-Schema/fractionDigitsformoneytype.htm
0
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 250 total points
ID: 40552303
The issue you might be having with the type you are using is the base type
<xs:restriction base="xs:string">
you should not use strings if your aim is to do calculations, use decimal instead.
Note that I posted a similar reply in an earlier question of yours
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/Q_28596088.html#a40547843
<xs:pattern value="\p{Nd}+(\.\p{Nd}\p{Nd})" />
is very similar to what I posted there
"\p{Nd}" is a regular expression indication for a decimal number... as is "\d",
consider the two equivalent, other than the base type
As I said in that other question, you would use the patern facet (one way to restrict the base type) if you need exactly 2 decimals as the fractional part

You are posting a number of questions, sometimes it is better to ask some extra information in an existing question, rather than starting yet another question that is hardly any different. We do give feedback even after you closed a question.
Try to really understand what we post before jumping to the next question... this forum will serve you as a better learning aid that way

Michael74's suggestion is not different from what I gave you in that other question
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/Q_28596088.html#a40547824
fractionDigits serves as a limitation, not as an exact number
so
99.99 is OK
99.9 is OK too
99.999 is not OK
If that is sufficient restriction for your purposes, I recommend that way
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question