Jump to content
Sign in to follow this  
domingoazul

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

Share this post


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.

Share this post


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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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...
Sign in to follow this  

×
×
  • Create New...