Solved

XSD:  numeric types

Posted on 2015-01-13
2
148 Views
Last Modified: 2015-01-14
I can create a date on an XSD as follows:

<xs:element minOccurs="0" name="curdate" type="xs:date"/>

Open in new window


I can define a string using xs:string

I can define integers using xs:integer

How can I define the following value (to represent cash)

999.99

Open in new window


(I will eventually have this in a repeating field and will need to sum them up, if that makes any difference)

Thanks
0
Comment
Question by:Anthony Lucia
  • 2
2 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40547824
Make a simpleType with a restriction facet

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="currency" >
        <xs:simpleType>
            <xs:restriction base="xs:decimal">
                <xs:fractionDigits value="2"></xs:fractionDigits>
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
</xs:schema>

Open in new window

0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 40547843
Or if you need it to be exactly 2 fractional digits

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="currency" type="cur-type"/>
    
    <xs:simpleType name="cur-type">
        <xs:restriction base="xs:decimal">
            <xs:pattern value="\d+\.\d{2}"></xs:pattern>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

Open in new window


Note that I made the type a named simple type, so you can reuse it for the list
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

Title # Comments Views Activity
strDist challenge 35 84
topping2 challenge 13 61
word0 challenge 3 58
Unexpected HttpURLConnection connection behavior 2 52
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, …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

760 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

18 Experts available now in Live!

Get 1:1 Help Now