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

StackOverflow https://stackoverflow.com/questions/13800461

  •  06-12-2021
  •  | 
  •  

Вопрос

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?

Это было полезно?

Решение

  • 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.

Другие советы

xsd allows the amount of an item could appear, add this to your isbn element xsd declaration

minOccurs="0" maxOccurs="1"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top