473,396 Members | 1,918 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,396 software developers and data experts.

Possible to create XSD for checking element interdependecies?

Hi,

I was wondering if anyone knows if this is possible. I have the
following simple xml document as follows:

<test>
<field1>Value1</field1>
<field2>Value2</field2>
</test>

I would like to create an XSD which validates that if the "field1"
element contains a value, then "field2" must also contain a value. And
also the other way around, if "field2" contains a value, then "field1"
must contain a value. However, if both fields do not contain values
then no validation errors occur. Any ideas? Thanks!
Jul 20 '05 #1
1 1510
Can't do it as stated. You can't have the type of one element (empty or not)
depend on the type of another, or any other test that amounts to the same
thing.

What you can do is require that if field1 is specified then field2 must be
specified, and vice versa. Since you can require that field1 and field2 have
values, this amounts to the same thing. One such schema fragment is:

<element name="test">
<complexType>
<complexContent>
<sequence minOccurs="0">
<element name="field1" type="integer"/>
<element name="field2" type="integer"/>
</sequence>
</complexContent>
</complexType>
</element>

(You would have no problem writing a schema per your original problem
statement in RELAX NG.)

Bob Foster

"ranma79" <ra*****@comcast.net> wrote in message
news:31*************************@posting.google.co m...
Hi,

I was wondering if anyone knows if this is possible. I have the
following simple xml document as follows:

<test>
<field1>Value1</field1>
<field2>Value2</field2>
</test>

I would like to create an XSD which validates that if the "field1"
element contains a value, then "field2" must also contain a value. And
also the other way around, if "field2" contains a value, then "field1"
must contain a value. However, if both fields do not contain values
then no validation errors occur. Any ideas? Thanks!

Jul 20 '05 #2

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

Similar topics

1
by: Ulf Heyder | last post by:
Hello, I have to deal with some xml schemas from a third party. This schema contains the following complex type. <?xml version="1.0"?> <xsd:schema ... elementFormDefault="qualified"> .......
8
by: Fabri | last post by:
Is it possible, as IE does in Windows Update, to ask onbeforeunload if the user want really close window (or tab) clicking on close (X) of the window? This window isn't opened by window.open....
2
by: MT | last post by:
Hi, I am currently validating an XML file against a Schema using XMLValidatingReader. The schema actually contains ranges for particular elements and I have been using it to detect range errors...
3
by: b0yce | last post by:
Hi Group, I think I have found a problem with the <xsl:element> when being transformed by the .NET xmlTransform class. When using XmlSpy for development and debugging, the <xsl:number>...
11
by: Brent Ritchie | last post by:
Hello all, I have been using C# in my programming class and I have grown quite fond of C# properties. Having a method act like a variable that I can control access to is really something. As...
14
by: hgraham | last post by:
Hi, I'm trying to understand how to work the dom, and all I'm trying to do is insert a link right before another link in the html based on it's href value. This isn't a real world example - I'm...
4
by: ronc85 | last post by:
I'm using ASP.NET 2.0 and C#. With the FileUpload control is it possible to set Wildcards (e.g., *.xls and *.doc) so that when the user clicks the Browse button it defaults to Excel and/or Word...
2
markmcgookin
by: markmcgookin | last post by:
Hi Folks, Bear with me if this sounds stupid pls! I have an xsl doc that is translating one type of xml to another (still with me?) I was wondering, is it possible to do the same thing to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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...

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.