XSD Help

Link. September 22, 2002. Comments [3]. Posted in: XML
I was fooling around a few days ago, writing an Xml Schema for an XML configuration file for a personal project I'm working on, and ran into something I don't know how to describe in XSD.... well, actually I'm not even sure it is entirely possible.

Basically, I wanted to have a section of the file contain something like this:

<condition>
   <from>some string</from>
   <to>some other string</to>
</condition>

The problem was that as I wanted it to be, the condition element could conain either the from element, the to element, or both, but at least one of the had to be present.

So, obviously, I know how to use minOccurs and maxOccurs, but that would only allow me to specify the frst condition, but not make it so that at least one of them was present. Neither did I find a way to do it using xsd:choose and friends.

So, is it possible to do, and if so, how? I'd appreciate any tips you could offer (and a pointer to the XSD spec section that makes it possible, if you're able to provide one)!



Sunday, September 22, 2002 3:18:03 PM (SA Pacific Standard Time, UTC-05:00)

This is untested but I think it will get you what you want:



<xsd:choice>

<xsd:sequence>

<xsd:element ref="from" />

<xsd:element ref="to" minOccurs="0" />

</xsd:sequence>

<xsd:element ref="to" />

<xsd:choice>

Sunday, September 22, 2002 3:20:02 PM (SA Pacific Standard Time, UTC-05:00)

Oops.



<xsd:choice>

  <xsd:sequence>

    <xsd:element ref="from" />

    <xsd:element ref="to" minOccurs="0" />

  </xsd:sequence>

  <xsd:element ref="to" />

</xsd:choice>

Tuesday, December 17, 2002 3:01:08 PM (SA Pacific Standard Time, UTC-05:00)

Sir,



Actually, I have similar kind of problem.



I am trying to bulkload a XML file into the database using XSD.



But I require a condition.

The tags are as follows



<SpecialTopic selected="False" SpecialTopicID="1" GrantNumberID= "1" />



<SpecialTopic selected="True" SpecialTopicID="1" GrantNumberID="1" />



I want to upload SpecialTopicID and GrantNumberID attribute of the tags based on the value of the

selected attribute.

If the value of the selected attribute is "True" then I want to bulk load SpecialTopicID and GrantNumberID otherwise I don't.



I would greatly appreciate it if someone could help me with the xsd.



Thanks,



Bhisham Asnani

Bhisham Asnani
Comments are closed.

About

Tomas Restrepo is co-founder of devdeo. His interests include .NET, Connected Systems, PowerShell and, lately, dynamic programming languages. More...

email: tomas@winterdom.com
msn: tomasr@passport.com
twitter: tomas_restrepo

Technorati Profile

devdeo logo

View my profile on LinkedIn

MVP logo

Syndicate

Ads


Links

Categories

Statistics

Total Posts: 1006
This Year: 76
This Month: 7
This Week: 0
Comments: 771

Blogroll

Post Archive

Other

Copyright © 2002-2008, Tomas Restrepo.

Powered by: newtelligence dasBlog 1.9.7174.0

Sign In