Reputation: 412
I'm currently trying to develop a XSD Schema for invoicing information which can be seen at http://intranet.servofarma.com/xml/schema/facturas.xsd.
My question is how can I make the contents of nroFactura
element unique across a XSD instance document?. I tried to use <unique>
but it is not clear to me how to use this constraint.
Upvotes: 0
Views: 136
Reputation: 21638
I don't think you can get a more concise answer than @Michael's (+1); still, I think you might also benefit from these additional clarifications.
Given your XSD, the Y in Michael's 'notation' can only be facturas
, since it is the only element in your XSD.
The modification:
<element name="facturas" type="tns:facturasType">
<unique name="pk1">
<selector xpath="tns:factura/tns:nroFactura"/>
<field xpath="."/>
</unique>
</element>
The result then looks like this:
One more thing I would mention is the use of .//
vs. being specific. The former is a great way to get things started; it may prove also hard to deal with in large XSDs where tags may be "reused" in different context. I would say it is a better practice to be as specific as possible than trying to match everything... unless, of course, that is the requirement.
Upvotes: 0
Reputation: 163262
The "unique" constraint in XSD allows you to say "every X within a given Y must have a unique value for Z". The constraint goes on the definition of Y. The xs:selector defines an XPath expression to select X from Y (for example, .//nroFactura), and the xs:field defines an XPath expression to select Z from X (for example, "." selects the string value of the element itself)
Upvotes: 1