Jump to content

to associate element content with its attribute


domingoazul

Recommended Posts

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

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

Type what? Is it in the tutorial?
I meant the complexType definition
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.
Ok
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.
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

  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...