Solved

What XSD format is this

Posted on 2015-01-15
2
97 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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

785 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