Jump to content

to associate element content with its attribute


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 post
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 post
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 post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...