Solved

XSD:  numeric types

Posted on 2015-01-13
2
150 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet web applications   metadata-complete="true" or false 3 44
Powershell XML in variable 4 21
How do I remove an object from a 3 27
Chrome and Firefox Java 5 34
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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
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:

831 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