XML schema unique child elements

artheboss

New Member
I am trying to validate that a parent has unique child elements by the element name.I also need to validate that at least one of the possible elements exists.Example\[code\]<StorageTypes> <Status/> <Warning/> <Error/> </StorageTypes> \[/code\]Would be valid but\[code\]<StorageTypes> <Status/> <Status/> <Warning/> <Error/> </StorageTypes> \[/code\]and \[code\]<StorageTypes> </StorageTypes> \[/code\]would be invalid.I have tried using xs:unique, selecting the the current node, but am unable to generically select the elements with the field element.The below acheives what I am looking to do but it is not the robust solution I am looking for. I would like to be able to add more Types with out changing the xpath for every change.\[code\]<element ect.> <xs:unique name="something"> <xs:selector xpath="."/> <xs:field xpath="Status"/> <xs:field xpath="Warning"/> <xs:field xpath="Error"/> </xs:unique></element>\[/code\]Is this possible? Is this good practice? Any advice would be appreciated.
 
Back
Top