473,546 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>5 12</minInclusive>
</RAM>
-OR-
<cost maxExclusive = "1000"/>

or something similar.

Can this be done?

TIA
Jul 20 '05 #1
1 1273


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>5 12</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="unbo unded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="ram">
<xs:simpleTyp e>
<xs:restricti on base="xs:positi veInteger">
<xs:minInclusiv e value="512" />
<xs:maxInclusiv e 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:noNamespace SchemaLocation= "test20040411Xs d.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
454
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 that the properties are readonly in .Net. How would I do the same as I used to in 6? I am doing the time honoured only allowing of numbers in a text...
4
4620
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 or field public? Thanks, Dennis
2
1667
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 System
12
1765
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; std::vector<AbstractBase*> vec; vec.push_back(&i); vec.push_back(&f);
2
1572
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 very light-weight Schema). One of the built-in types is called "ref", and its defined values are location paths to other elements in the instance...
1
2413
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
8699
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 the title field gets its information from a previouse page so its value can easily be over 40 chars. (I can not restrict the length on the previouse...
1
1357
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 to see all files. is there any way to restrict file types like,i want to select only xml files to be uploaded. and i want to display some message...
1
1968
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 only be instantiated with unsigned types. template <typename unsigned T> inline T id(T *i) {
0
7507
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7698
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5361
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.