473,657 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Developing a contrained based XSD?

Hi, I was wondering, is it possible to restrict the value of an element
based on the type element? For example,

<mytypes>
<mytype>
<name>value1</name>
<type>double</type>
<value>123.89 </value>
</mytype>

<mytype>
<name>value2</name>
<type>integer </type>
<value>123</value>
</mytype>

<mytype>
<name>value3</name>
<type>short</type>
<value>123</value>
</mytype>
</mytypes>

Now, the specification would for the XSD would be as follows:

a) 1 or more 'mytype'
b) 'type' element should constrain 'value'

If anyone has any ideas as to how to develop this in XSD, please post
to the group.

Thanks in advance,

-Conrad

Jul 20 '05 #1
6 2210


co******@runbox .com wrote:
Hi, I was wondering, is it possible to restrict the value of an element
based on the type element? For example,

<mytypes> <mytypes xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<mytype>
<name>value1</name>
<type>double</type>
<value>123.89 </value>


You can use stuff like
<value xsi:type="xs:do uble">123.89</value>
if you want to refer to the types XML schema knows.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Con
Hi, thanks to responding to my post. Anyway, if type tag is of the
following:

short
int
long int
float
double

How does enforce the type of value in the value tag?

Thanks in advance,

-Conrad

Jul 20 '05 #3
/Con/:
Hi, thanks to responding to my post. Anyway, if type tag is of the
following:

short
int
long int
float
double

How does enforce the type of value in the value tag?


Define a base type for your "mytype" element, like:

<xs:complexTy pe name="MyType">
<xs:sequence>
<xs:element name="name" type="xs:string " />
<xs:element name="type" type="ValueType s" />
<xs:element name="value" type"xs:anySimp leType" />
</xs:sequence>
</xs:complexType>

<xs:element name="mytype" type="MyType" />

Define the "ValueTypes ":

<xs:simpleTyp e name="ValueType s">
<xs:restricti on base="xs:string ">
<xs:enumerati on value="short" />
<xs:enumerati on value="int" />
<xs:enumerati on value="long int" />
<xs:enumerati on value="float" />
<xs:enumerati on value="double" />
</xs:restriction>
</xs:simpleType>

Define the derived types:

<xs:complexTy pe name="MyShortTy pe">
<xs:complexCont ent>
<xs:restricti on base="MyType">
<xs:sequence>
<xs:element name="name" type="xs:string " />
<xs:element name="type" type="ValueType s" fixed="short" />
<xs:element name="value" type"xs:short" />
</xs:sequence>
</xs:restriction>
<xs:complexCont ent>
</xs:complexType>

<!-- and so on -->

Then use the xsi:type attribute in the instance document:

<mytype>
<name>value2</name>
<type>int</type>
<value>ivalid still valid</value>
</mytype>

<mytype xsi:type="MySho rtType">
<name>value3</name>
<type>short</type>
<value>123</value>
</mytype>

I haven't tried it but I think it should work. :-) Similar example
<http://www.w3.org/TR/xmlschema-0/#abstract> is given in the "XML
Schema Part 0: Primer", although it forces the usage of the xsi:type
attribute, declaring the base type abstract.

--
Stanimir
Jul 20 '05 #4
Con
Hey Stanimir, is it possible to not use the xsi:type="MySho rtType"? I
would like to check validation based on the value of type tag and the
value tag.

Thanks in advance,

-Conrad

Jul 20 '05 #5
/Con/:
Hey Stanimir, is it possible to not use the xsi:type="MySho rtType"? I
would like to check validation based on the value of type tag and the
value tag.


AFAIK, using XML Schema - it is not possible.

--
Stanimir
Jul 20 '05 #6
/Stanimir Stamenkov/:
/Con/:
Hey Stanimir, is it possible to not use the xsi:type="MySho rtType"? I
would like to check validation based on the value of type tag and the
value tag.


AFAIK, using XML Schema - it is not possible.


You may use substitution groups, however... where you get
differently named elements for the different types:

...

<xs:element name="mytype" type="MyType" abstract="true" />

...

<xs:element name="myshortty pe" substitutionGro up="mytype">
<xs:complexType >
<xs:complexCont ent>
<xs:restricti on base="MyType">
<xs:sequence>
<xs:element name="name" type="xs:string " />
<xs:element name="type" minOccurs="0"
type="ValueType s" fixed="short" />
<xs:element name="value" type"xs:short" />
</xs:sequence>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
</xs:element>

<xs:element name="myinteger type" substitutionGro up="mytype">
...
</xs:element>

...

Now wherever there's a "mytype" element particle in the schema,
there should be one of the elements from the substitution group
headed by "mytype" in the instance document. The "mytype" itself
can't appear in the instance when declared abstract in the schema.
You would notice the "type" child becomes obsolete, in the above
example.

<xs:schema ...
<xs:element name="mytypes">
<xs:complexType >
<xs:sequence>
<xs:element ref="mytype" maxOccurs="unbo unded" />
</xs:sequence>
</xs:complexType>
</xs:element>
...
</xs:schema>
<mytypes>

<myshorttype>
<name>value1</name>
<value>123</value>
</myshorttype>

<myintegertyp e>
<name>value2</name>
<value>12345678 9</value>
<myintegertyp e>

</mytypes>
Still, I suppose it is not exactly what you want. :-)
* http://www.w3.org/TR/xmlschema-0/#SubsGroups

--
Stanimir
Jul 20 '05 #7

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

Similar topics

9
1595
by: john | last post by:
Hi I am developing a timesheet system. It will have 3 levels of access 1)Administrator 2)Approver -- Will approve or reject the timesheet filled by employees 3)Employees -- Fill in the timesheet which will ontain info like start time & end for task & task description. There will be different projects with different employees & approvers Also I need to genrate reports like timesheet for an employee for this particular week or month.Or...
5
1549
by: Bill | last post by:
Good Day; I would appreciate assistance developing a query that I haven't been able to develop without using a second table. I wish to count the number of records that are still open on the first of each month. Each record has an open date and a close date or the close date is null i.e., the record is not yet closed. I've previously beaten this by building a table, simply a list of the dates for the first of each month for the next...
4
2433
by: Jason Huang | last post by:
Hi, I am thinking in comparing developing speed between C# Windows Form and C# Web Form applications. Assuming the scenario is that we have 2 C# coding engineers, engineer A has 2 years experience on developing C# windows form, engineer B has 2 experience on developing C# web form, B also knows Javascript as well. They both has the same apprehesnion for the Database things, they all devote themselves completely to their developing...
7
1824
by: Chris Marsh | last post by:
All I've been asked run a VM on my development machine, with Windows Server 2003 installed. I've also been asked to then develop against this environment from the host machine, using Visual Studio 2003. Questions: 1. Is it even possible to use VS 2003 to develop when all files and IIS are on a remote machine or VM?
0
8411
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4173
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
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
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.