aspose file tools*
The moose likes XML and Related Technologies and the fly likes how can i use xs:unique for avoiding duplicacy of attribute name in xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "how can i use xs:unique for avoiding duplicacy of attribute name in xml" Watch "how can i use xs:unique for avoiding duplicacy of attribute name in xml" New topic
Author

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

Tej Ghag
Greenhorn

Joined: Mar 31, 2011
Posts: 10

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

Joined: Jan 18, 2011
Posts: 535
    
    3
>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

Joined: Mar 31, 2011
Posts: 10

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

Joined: Jan 18, 2011
Posts: 535
    
    3
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

Joined: Mar 31, 2011
Posts: 10

brilliant ..... many Thanks tsuji,
It works ....(me idiot didn't realise that order of xs:unique!)


tc!

cheers,
Tej
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
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

Joined: Mar 31, 2011
Posts: 10

No worries at all!
I realised that might be a typo error

tc!

cheers, Tej
 
jQuery in Action, 2nd edition
 
subject: how can i use xs:unique for avoiding duplicacy of attribute name in xml