?
Solved

XSD:  numeric types

Posted on 2015-01-13
2
Medium Priority
?
164 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

809 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