domingoazul Posted March 22, 2007 Share Posted March 22, 2007 Hello,I want to associate the content of an element called 'user' depending on the value of its attribute 'profile'.Example: <user profile="student"> <personalInfo> ... </personalInfo> <contactInfo> ... </contactInfo> <profileInfo> <studies>Biology</studies> </profileInfo></user><user profile="teacher"> <personalInfo> ... </personalInfo> <contactInfo> ... </contactInfo> <profileInfo> <department>Mathematics</department> </profileInfo></user> 'personalInfo' and 'contactInfo' contain same elements, but not 'profileInfo'. I know that one element must have only one definition, so I define the elements on profileInfo with minOccurs="0" and maxOccurs="1". Is it any way to modify the schema and force the 'user' element to use the corresponding elements of 'profileInfo' depending on the value of its attribute 'profile'?Thank youIñaki Link to comment Share on other sites More sharing options...
domingoazul Posted March 22, 2007 Author Share Posted March 22, 2007 Ups, I have just found the Type Substitutability.My question now is reduced to: can I link the type with the value of the attribute? Link to comment Share on other sites More sharing options...
boen_robot Posted March 22, 2007 Share Posted March 22, 2007 Type what? Is it in the tutorial?Anyhow, I don't think what you're asking is possible in Schema 1.0. The value or existence of one node cannot force the value or existence of another node.The closest thing to what you're asking is to have a "choose" statement between two different elements, each enforcing it's own child elements. Those elements could actually refer to other elements, which could be the same. This makes the schema a little more verbose, but it kind'a works for what you want in the end. Link to comment Share on other sites More sharing options...
domingoazul Posted March 22, 2007 Author Share Posted March 22, 2007 Type what? Is it in the tutorial?I meant the complexType definitionAnyhow, I don't think what you're asking is possible in Schema 1.0. The value or existence of one node cannot force the value or existence of another node.OkThe closest thing to what you're asking is to have a "choose" statement between two different elements, each enforcing it's own child elements. Those elements could actually refer to other elements, which could be the same. This makes the schema a little more verbose, but it kind'a works for what you want in the end.Thanks, it seems to will work. I was searching about something like this 'choose' statement you mention but I can not found anything. Is it part of XML Schema? Link to comment Share on other sites More sharing options...
boen_robot Posted March 22, 2007 Share Posted March 22, 2007 Opps... my bad. I meant "choise". I mix it up with XSLT's "choose". Yes, it's part of XML Schema. Look at complex indicators. Link to comment Share on other sites More sharing options...
domingoazul Posted March 31, 2007 Author Share Posted March 31, 2007 Ok, thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now