F. Nogatz, and J. Kalkus. Declarative Programming and Knowledge Management, page 187-197. (2018)
XML Schema is a well-established mechanism to define the structure and constrain the content of an XML document. While this approach taken by itself is declarative, currently available tools for XML validation are not. In this paper we introduce an implementation of an XSD validator in SWI-Prolog, made publicly available as the package library(xsd). Our approach is based on flattening the XSD and XML documents into Prolog facts. The top-down validation makes great use of Prolog's backtracking and unification capabilities. To ensure the compliance to the XSD standard and to support the test-driven development, we have created a test framework based on the Test Anything Protocol and SWI-Prolog's quasi-quotations.