Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 12th, 2009, 05:21 AM
Authorized User
 
Join Date: Jun 2005
Location: , , Philippines.
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default Defining restrictions based on element/attribute values

How can I implement a custom restriction based on element or attribute value.

I have the following xml

<courses>
<course id="1">
<students>25<students>
</course>
<course id="2">
<students>30<students>
</course>
</courses>

I want to define a valid value for <students> element for each course id. There can be lots of courses. Say maximum value for students in course 1 is 30.

Some elements might be required based on the value of the course id.


How do I define an xsd for these?Is it possible?
__________________
\"Dont you ever give up!\"
Reply With Quote
  #2 (permalink)  
Old May 12th, 2009, 06:51 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

XSD 1.0 doesn't support this feature (known as "co-occurrence constraints"). You can do it in XSD 1.1 using assertions. However, I'm sceptical whether this is a good design: the maximum number of students on each course looks to me like data, not metadata, and I'm not sure it really belongs in a schema.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #3 (permalink)  
Old May 12th, 2009, 08:11 PM
Authorized User
 
Join Date: Jun 2005
Location: , , Philippines.
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default

mkhay,
I just used that as an example, I am really after the co-occurrence constraints.

Thank you very much..
__________________
\"Dont you ever give up!\"
Reply With Quote
  #4 (permalink)  
Old May 13th, 2009, 03:55 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

You can try out assertions (and conditional type assignment, which is sometimes a better approach to the problem) using Saxon-SA 9.1
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM
Match element based on attribute of child? transom XSLT 1 September 11th, 2005 03:26 PM
Rules based on attribute values... jacob XML 2 July 6th, 2005 01:50 PM
Modeling with restrictions on attribute value jacob XML 0 June 3rd, 2005 07:01 AM
XPath - Selecting nodes based on attribute values billy_bob_the_3rd XML 4 December 1st, 2004 06:12 PM



All times are GMT -4. The time now is 08:58 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.