File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML: Unique

 
Abhi Venu
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Paul Clapham
Sheriff
Pie
Posts: 20160
23
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So for each Person/Address you require non-duplicate country elements? Why not just say that in your schema then?
 
Abhi Venu
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20160
23
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all help Do any other have any idea
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic