Solved

What XSD format is this

Posted on 2015-01-15
2
95 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now