Solved

XSD:  numeric types

Posted on 2015-01-13
2
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
learn programming 8 94
ArrayList Adding/settign data 3 37
Access blocked to XML files other than sitemap.xml? 4 72
IBM TS2900 (3572) Tape Autoloader Java? 12 106
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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

732 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