Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-27-2003, 10:36 PM   #1
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint Debian Edition (LMDE)
Posts: 215

Rep: Reputation: 31
XML Schema complexType

I want to be able to do the following in XML:

   <amount currency="USD">100.00</amount>
How would I write the XML schema for this? My first attempt at a solution was:

<xsd:schema xmlns:xsd="">

   <xsd:complexType name="amountType" type="xsd:float">
      <xsd:attribute name="currency" type="xsd:string"/>

   <xsd:element name="transaction">
         <xsd:element name="amount" type="amountType"/>

That's obviously wrong because complexType cannot have a type attribute. How do I specify that <amount> has a currency attribute, and can have a positive floating point value as content?
Old 12-28-2003, 04:01 AM   #2
Senior Member
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
I'm on the very early stages of XML but it could be done something like this I think. Basically define your own simple type for a currency value.. You can also use xsdresicion value="10" or whatever to define the total number of digits used including decimal and xsd:scale for the number of decimal places rather than fractionDigits. There is probably a better, convaluted way,as thisvery much a beginner here but all practice is good

<?xml version="1.0"?>

<xsd:schema xlmns="">
  <xsd:element name="currencyTransaction">
      <xsd:element name="transaction" type="transactionType" minOccurs="0" maxOccurs="unbounded" / >  

<xsd:complexType name="transactionType">
  <xsd:element name="transactionCurrency" type="xsd:string"/>

 <xsd:attribute name="transactionValue" type="currencyValue" use="required"/> 


 <xsd:restriction base="xsd:decimal">
  <xsd:minInclusive value="0"/>
  <xsd:fractionDigits value="2"/>


Last edited by Looking_Lost; 12-28-2003 at 04:06 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
checking for XML::Parser... configure: error: XML::Parser perl module is required for kornerr Linux - General 11 11-16-2008 07:24 AM
nis.schema error naveenlinux SUSE / openSUSE 0 11-25-2005 04:02 AM
Ldap schema error mesh2005 Linux - Networking 0 11-20-2005 04:16 AM
Partition Schema tomap Linux - Newbie 4 10-10-2004 01:53 PM
Partition Schema bmagill Slackware - Installation 3 05-27-2004 12:20 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:21 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration