Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 20th, 2009, 10:05 AM
Authorized User
 
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
Default Restricting attribute value in XMl Schema

Hi All,
I have an XMl structure and i am creating XML Schema document for validating xml document.
What i want that for a particular element it should not allow same attribute name.
for example below is the XML structure :
<News>
<Regional>
<Report Region="Asia">
<Title></Title>
<Story></Story>
</Report>
</Regional>
</News>
What i want in Xml Schema how can i restrict that in the "Region" Attribute of elemet <Report> value "Asia" occure only once. It should not allow two <Report> element with the value "Asia" in Region Attribute.
Thanks for the help
-John
 
Old October 20th, 2009, 10:13 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If you do not want to allow two Report elements with the same Region attribute value in general then you can define a unique constraint e.g.
Code:
<xs:element name="Regional">
   <xs:complexType>
     <xs:sequence maxOccurs="unbounded">
        <xs:element name="Report">
           ...
        </xs:element>
     </xs:sequence>
  </xs:complexType>
  <xs:unique name="unique-region">
     <xs:selector xpath="Report"/>
     <xs:field xpath="@Region"/>
  </xs:unique>
</xs:complexType>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
nelly78 (October 20th, 2009)
 
Old October 20th, 2009, 10:55 AM
Authorized User
 
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Thanks Martin, Its working ...
 
Old October 20th, 2009, 10:56 AM
Authorized User
 
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Thanks Martin, Its working.





Similar Threads
Thread Thread Starter Forum Replies Last Post
create xml from xml schema in java zhebincong XML 1 October 6th, 2009 04:10 AM
how to refer any schema attribute in one file while it is declared in other maryj XML 2 June 21st, 2009 01:18 PM
What's the use of XML Schema?! janise XML 2 August 29th, 2004 05:31 AM
xml schema help allang XML 0 August 19th, 2004 09:58 PM
XML, XML Schema, JavaScript, ASP cyberjames2003 XML 0 June 4th, 2003 04:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.