Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > restricting data types

Reply
Thread Tools

restricting data types

 
 
Ranjit
Guest
Posts: n/a
 
      04-10-2004
Hi,

This may be quite a dumb question but I have not been able to address
this convincibly. How can I specify restrictions on basic data types in
my xml?

I did some search and came across Schema Component Constraints such as
minInclusive, maxExclusive etc.

But I was wondering if I could refer to them in my xml.
e.g.
<RAM>
<minInclusive>512</minInclusive>
</RAM>
-OR-
<cost maxExclusive = "1000"/>

or something similar.

Can this be done?

TIA
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-11-2004


Ranjit wrote:

> This may be quite a dumb question but I have not been able to address
> this convincibly. How can I specify restrictions on basic data types in
> my xml?
>
> I did some search and came across Schema Component Constraints such as
> minInclusive, maxExclusive etc.
>
> But I was wondering if I could refer to them in my xml.
> e.g.
> <RAM>
> <minInclusive>512</minInclusive>
> </RAM>
> -OR-
> <cost maxExclusive = "1000"/>
>
> or something similar.
>
> Can this be done?


You can write an XML schema that defines the structure and restrictions
for your XML instance files, check out
http://www.w3.org/TR/xmlschema-0/

For instance you could define a schema as follows

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema">

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="ram" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="ram">
<xs:simpleType>
<xs:restriction base="xsositiveInteger">
<xs:minInclusive value="512" />
<xs:maxInclusive value="1024" />
</xs:restriction>
</xs:simpleType>
</xs:element>

</xs:schema>

and then a validating XML parser would flag the last <ram> element in
the following XML instance file as having a wrong value:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test20040411Xsd.xml ">
<ram>512</ram>
<ram>768</ram>
<ram>1024</ram>
<ram>256</ram>
</root>
--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Restricting template parameters to signed or unsigned types, but notboth Damian C++ 2 04-07-2008 08:45 PM
equivalent c data types for vc++ data types ramu C Programming 2 02-20-2006 09:33 AM
Can XSD simple types be derived from complex types? Soren Kuula XML 2 12-01-2005 07:51 PM
Where are ref types that are members of value types stored? Sathyaish ASP .Net 2 05-22-2005 07:32 PM
Restricting Upload File Types chuckdfoster ASP .Net 2 05-13-2005 03:16 PM



Advertisments