473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

restricting data types

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
Jul 20 '05 #1
1 1263


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 xmlns:xs="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="xs:positiveInteger">
<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 xmlns:xsi="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/

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Robin | last post by:
H In VB6 I used to trap by keycode on the keydown event and if the keystroke didn't fit into my criteria I would set the value of the keycode to 0 which would invalidate the keystroke. I noticed...
4
by: Dennis C. Drumm | last post by:
Is there a way with C# to allow one class access to a method or field of another class, without making that method or field visible to all other classes, as would be the case when making the method...
2
by: chuckdfoster | last post by:
I have a page that users upload files. Is there a way to restrict the file types that they can upload? thanks, -- Chuck Foster Programmer Analyst Eclipsys Corporation - St. Vincent Health...
12
by: Rennie deGraaf | last post by:
I have a system that looks like this: class AbstractBase { /* ... */ }; template <class T> class Impl : public AbstractBase { /* ... */ }; // ... Impl<int> i; Impl<float> f;...
2
by: Arndt Jonasson | last post by:
This is a modelling style question, I think. I am working with a somewhat XML Schema-like formalism which defines the structure of an instance document, supplying a number of built-in types (a...
1
by: KK | last post by:
Dear All I'm planning to develop a class for my project which can operate on only few known data types For example : public class MyOperations<T> { public T ChangeBounds()
8
by: sneddo | last post by:
Ok I am trying to do the above, I have got a script that will restrict the length but it requires the user to enter the field and hit a key, before it will work. This would normaly be find, but...
1
by: ettarameshreddy | last post by:
Hi, I got a problem like i write a input file element like this <input type="file" name="testfile" > When i execute this i get a text box with browse. when i click browse i am abl e...
1
by: Damian | last post by:
Hi there, I would like to restrict a template parameter to a template functioned to either a signed or unsigned type, but not both. For example, the following templated function should ideally...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.