Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can i use xs:unique for avoiding duplicacy of attribute name in xml

 
Tej Ghag
Greenhorn
Posts: 10
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a requirement where in i need to restrict the same attribute name to appear twice in xml file for tht given element!

for e.g
<FulfilmentData Name="EmbossLine1" Value="5555 1602 2000 0000" Encoding="None"></FulfilmentData>
<FulfilmentData Name="EmbossLine1" Value="1111 1602 1111 0000" Encoding="None"></FulfilmentData>

here EmbossLine1 appeared twice, so jaxb2 while unmarshalling takes latest value without throwing any error!

I tried <xs:unique .... for this purpose but unlucky ...i might be missing something or doing in the wrong way ...
my xsd looks like....


Will appreciate your kind help!

rgrds,
Tej
 
g tsuji
Ranch Hand
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>I got a requirement where in i need to restrict the same attribute name to appear twice in xml file
Do you mean you want it to appear exactly two times in different siblings named FilfilmentData or you do not want it to appear more than once...? I cannot make a clear deduction from what I read.
 
Tej Ghag
Greenhorn
Posts: 10
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnxs tsuji for your response!

Well, your later thought is right ....you do not want it to appear more than once ....... and FullfilmentData is an element having Name and Value as attributes so I want Name attribute to be restircted for Uniqueness means it shouldn't be repeated!

hope I'm clear this time?

 
g tsuji
Ranch Hand
Posts: 656
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification. In that case, it is the classic use of xs:unique which it is designed for.

However, it is important to place it at the correct place. The main thing is that the xpath acceptable in the xs:selector and xs:field is not the full set of xpath as specified in the xpath recommendation. Only a fairly small subset is allowed (otherwise, if you place it your way, one might think of an axis back-tracking to the element's parent etc..., but that is not allowed.)

The place of it should appear in the container element of FulfilmentData. A typical structure, but not necessary being so, may look like this. (The "name_of_parent_to_FulfilmentData" is of course figurative, it is your actual name used.)
 
Tej Ghag
Greenhorn
Posts: 10
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
brilliant ..... many Thanks tsuji,
It works ....(me idiot didn't realise that order of xs:unique!)


tc!

cheers,
Tej
 
g tsuji
Ranch Hand
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should have typed @Name, don't know why I typed @Encoding after scrolling up and down! Good to know you get the essence of it.
 
Tej Ghag
Greenhorn
Posts: 10
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No worries at all!
I realised that might be a typo error

tc!

cheers, Tej
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic