aspose file tools*
The moose likes XML and Related Technologies and the fly likes XML: Unique Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML: Unique" Watch "XML: Unique" New topic
Author

XML: Unique

Abhi Venu
Ranch Hand

Joined: Jul 09, 2009
Posts: 73

I have an XML file with following structure

<Dteails>
< Person>
<Address>
<country>India</country>
</Address>
<Address>
<country>India</country>
</Address>
</person>
< Person>
<Address>
<country>India</country>
</Address>
<Address>
<country>India</country>
</Address>
</person>
</details



There can be more than One person
For each person ther can be more than one address

Th restriction to be imposed are

No two addresss block under a person can have same country

< Person>
<Address>
<country>India</country>
</Address>

<Address>
<country>India</country>
</Address>
</person> This should not be allowed






But two diffrent persons can have same address in their country


< Person>
<Address>
<country>India</country>
</Address>
<Address>
<country>canada</country>
</Address>
</person>

< Person>
<Address>
<country>India</country>
</Address>
<Address>
<country>canada</country>
</Address>
</person>
This should be allowed


I used

<xs:unique name="country_Constraint1" msdata:ConstraintName="Constraint1" >
<xs:selector xpath=".//Address" />
<xs:field xpath="country" />

Then it was disallowing two address blocks with same countries for a person

But the problem is that it also dont allows two diffrent persons can having same address in their country . i want the case two to be allowed.How can this be done.

How the path is choses according to selector Path specified

A table, a chair, a bowl of fruit and a violin; what else does a man need to be happy?:Einstein
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

So for each Person/Address you require non-duplicate country elements? Why not just say that in your schema then?
Abhi Venu
Ranch Hand

Joined: Jul 09, 2009
Posts: 73
In schema I used

<xs:unique name="country_Constraint1" msdata:ConstraintName="Constraint1" >
<xs:selector xpath=".//Address" />
<xs:field xpath="country" />
But it wont allow dupliacte country name in all address fields..that is not specific to person/address
My requirement is limiting the scope of uniqueness under each person

please tell how can i specify that in schema
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

Well, I know basically nothing about schema. So that's why I just made a general suggestion in my earlier post, rather than attempting to produce an actual correct schema. But you seem to have avoided paying attention to it. So let me have a go at changing your schema:

Now, that probably won't work either. I don't understand how the schema sets the context node for an XPath expression. But you're the one using schemas so perhaps you do. At any rate I leave you to fix it up.
Abhi Venu
Ranch Hand

Joined: Jul 09, 2009
Posts: 73
Thanks for all help Do any other have any idea
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: XML: Unique