LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
LinkBack Search this Thread
Old 12-27-2003, 10:36 PM   #1
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Ubuntu
Posts: 208

Rep: Reputation: 31
XML Schema complexType


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

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

Code:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

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

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

</xsd:schema>
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
Looking_Lost
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

Code:
<?xml version="1.0"?>

<xsd:schema xlmns="http://www.w3.org/2000/10/XMLSchema">
  
  <xsd:element name="currencyTransaction">
   <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="transaction" type="transactionType" minOccurs="0" maxOccurs="unbounded" / >  
    </xsd:sequence>
   </xsd:complexType>
  </xsd:element>

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

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

</xsd:complexType> 

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

</xsd:schema>

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


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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/Novell 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


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

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