473,398 Members | 2,120 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,398 software developers and data experts.

XSD - attribute level data validation

3
Hi all,

I have an XML in which i need to validate the attribute values based on another attribute value of the same tag.

For Example

Expand|Select|Wrap|Line Numbers
  1. <Employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  2.     <Emp>
  3.         <Column name="EName">Albert</Column>
  4.         <Column name="Age">27</Column>
  5.         <Column name="Dept">105</Column>
  6.     </Emp>
  7. </Employees>
  8.  
Question:
In the above under Employees / Emp / Column, if the attribute "name" has the value "Dept" then the value of the tag should be 105 or 106 or 107

Can anybody throw some light on how to achieve this through XSD.
Any help is highly appreciated

I have the below XSD generated though XMLSpy
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--W3C Schema generated by XMLSpy v2008 rel. 2 (http://www.altova.com)-->
  3. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  4.     <xs:element name="Column">
  5.         <xs:complexType>
  6.             <xs:simpleContent>
  7.                 <xs:extension base="ST_Column">
  8.                     <xs:attribute name="name" use="required">
  9.                         <xs:simpleType>
  10.                             <xs:restriction base="xs:string">
  11.                                 <xs:enumeration value="Age"/>
  12.                                 <xs:enumeration value="Dept"/>
  13.                                 <xs:enumeration value="EName"/>
  14.                             </xs:restriction>
  15.                         </xs:simpleType>
  16.                     </xs:attribute>
  17.                 </xs:extension>
  18.             </xs:simpleContent>
  19.         </xs:complexType>
  20.     </xs:element>
  21.         <xs:simpleType name="ST_Column">
  22.         <xs:restriction base="xs:string">
  23.             <xs:enumeration value="105"/>
  24.             <xs:enumeration value="27"/>
  25.             <xs:enumeration value="Albert"/>
  26.         </xs:restriction>
  27.     </xs:simpleType>
  28.     <xs:element name="Employees">
  29.         <xs:complexType>
  30.             <xs:sequence>
  31.                 <xs:element ref="Emp" maxOccurs="unbounded"/>
  32.             </xs:sequence>
  33.         </xs:complexType>
  34.     </xs:element>
  35.     <xs:element name="Emp">
  36.         <xs:complexType>
  37.             <xs:sequence>
  38.                 <xs:element ref="Column" maxOccurs="unbounded"/>
  39.             </xs:sequence>
  40.         </xs:complexType>
  41.     </xs:element>
  42. </xs:schema>
  43.  
Thanks
Naga
Jan 27 '09 #1
1 2301
jkmyoung
2,057 Expert 2GB
This is called a co-occurence constraint and is not checkable strictly through xml schema (1.0). Are you open to using extensions, such as schematron or RelaxNG? It is available in Xml Schema 1.1, but there are not as many applications which validate to that.
http://www.ibm.com/developerworks/library/x-xml11pt2/
Jan 27 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: UndoMiel | last post by:
Hi, I have a situation where i would like to validate the occurance of certain elements, based on the value of an attribute. What is the "best" way to handle such validations? I am fairly new...
0
by: Ingrid | last post by:
Am I right in thinking that datatyping at element level ie <xs:element name="num" type="xs:integer"> and specifying a choice of attribute values ie <xs:attribute name="kind"> <xs:simpleType>...
6
by: anon | last post by:
Post Forwarding question...... For this control below, <asp:Button runat="server" PostTargetUrl="page2.aspx" /> The Attribute: PostTargetUrl="page2.aspx" Is this PostTargetUrl Attribute...
2
by: Kostas | last post by:
Just a quick question on this issue. Assume a small set of fixed values for a field. For instance Field Gender, values: Male, Female, Unknown If I create a Combo Box with the above values, I...
8
by: SL | last post by:
I try to validate against a schema a document stored in several files thanks to external entities. The parseur add a 'xml:base="url"' attribute on the root element of this sub-trees during parsing,...
2
by: Radu | last post by:
Hi. I have been working at home on a web project (VSNET 2005 SP1). Now I have brought the project at work, and I suddenly have plenty of warnings like: Validation (XHTML 1.0 Transitional) -...
3
by: Jon | last post by:
I have an xml document like so... <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:ng="http://newsgator.com/schema/extensions"> <channel> <title></title> <link></link>...
4
by: MonkeeSage | last post by:
Proposal: When an attribute lookup fails for an object, check the top-level (and local scope?) for a corresponding function or attribute and apply it as the called attribute if found, drop...
4
by: Stefan Hoffmann | last post by:
hi @all, I'm trying to validate a XML against a schema using the example from the MSDN: http://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings.validationtype.aspx In my case...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
0
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...
0
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,...
0
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...

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.