Search code examples
perlxsdxml-libxml

How do I defined unique constraint in xsd ? How can I achive error validation using xml-libxml?


With reference to topic, Perl, LibXML and Schemas

If I want to make the isbn tag to be an unique constraint, then what will be the change required in XSD. In addition to this, if I want to add validations for unique constraint using XML::LibXml, can I achieve the validations check using the same code? Can someone please explain with sample example with error in xml doc for unique constraint?


Solution

    • In regards of XSD schema enforcing key uniqueness: use the xs:unique element. More info in Enforcing Association Cardinality article, and take a look at the provided example XSD;
    • XML schema validation in Perl can be achieved using XML::Compile module, which wraps itself around XML::LibXML.