Abstract
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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
http://xerces.apache.org/ [accessed 12 March 2018], Apache License 2.0.
- 2.
https://www.oxygenxml.com/ [accessed 12 March 2018], proprietary license.
- 3.
http://www.saxonica.com/ [accessed 12 March 2018], Xsd 1.1 support in Saxon Enterprise Edition 9.5, proprietary license.
- 4.
http://www.jclark.com/sp/ [accessed 12 March 2018].
- 5.
xsd2json is in active use and maintained. It is available as open source at https://github.com/fnogatz/xsd2json (MIT License). Because of recent improvements, the constraint functors have been slightly changed compared to [16].
- 6.
Xml attributes in general do not have any namespaces. For special attributes like the declaration of the namespace prefix xs in xmlns:xs="\(\dots \)", this is handled separately.
- 7.
https://github.com/mndrix/regex [accessed 12 March 2018], The Unlicense.
- 8.
library(xsd) provides the options ’without-tabling’(Bool) and profile(Bool). The example in /test/example/choice_minmax returns: without memoisation 0.55s with 3,628,657 inferences; with memoisation 0.01s with 50,370 inferences (Swi–Prolog 7.7.5).
- 9.
https://travis-ci.org/ [accessed 12 March 2018].
- 10.
https://github.com/mndrix/tap [accessed 12 March 2018], The Unlicense.
- 11.
A list of currently supported Xsd features can be found at https://github.com/jonakalkus/xsd/blob/master/FEATURES.md [accessed 12 March 2018].
- 12.
The example in /test/example/sequence_unbounded* returns: Xsd with 200 lines of code in 0.11s with 281,288 inferences; 400 lines of code in 0.71s with 1,042,288 inferences (Swi–Prolog 7.7.5).
References
Bray, T., Paoli, J., Sperberg-McQueen, C.M., Maler, E., Yergeau, F.: Extensible markup language (XML). World Wide Web J. 2(4), 27–66 (1997)
Fallside, D.C., Walmsley, P.: XML schema part 0: primer second edition. W3C Recommendation (2004)
Gao, S., Sperberg-McQueen, C.M., Thompson, H.S., Mendelsohn, N., Beech, D., Maloney, M.: W3C XML schema definition language (XSD) 1.1 part 1: structures. W3C Candidate Recommendation (2009)
Clark, J., DeRose, S., et al.: XML path language (XPath) version 1.0 (1999)
Wielemaker, J., Schrijvers, T., Triska, M., Lager, T.: SWI-Prolog. Theor. Pract. Log. Program. 12(1–2), 67–96 (2012)
Specification of the Test Anything Protocol. https://testanything.org/tap-specification.html. Accessed 12 Mar 2018
Wielemaker, J., Hendricks, M.: Why it’s nice to be quoted: quasiquoting for prolog. In: Proceedings of 23rd Workshop on Logic-based Methods in Programming Environments (WLPE) (2013)
Beckett, D., McBride, B.: RDF/XML syntax specification (revised). W3C recommendation 10(2.3) (2004)
Wielemaker, J., Schreiber, G., Wielinga, B.: Prolog-based infrastructure for RDF: scalability and performance. In: Fensel, D., Sycara, K., Mylopoulos, J. (eds.) ISWC 2003. LNCS, vol. 2870, pp. 644–658. Springer, Heidelberg (2003). https://doi.org/10.1007/978-3-540-39718-2_41
Wielemaker, J., Huang, Z., Van Der Meij, L.: SWI-Prolog and the web. Theor. Pract. Log. Program. 8(3), 363–392 (2008)
Wielemaker, J., Beek, W., Hildebrand, M., van Ossenbruggen, J.: Cliopatria: a SWI-Prolog infrastructure for the semantic web. Semant. Web 7(5), 529–541 (2016)
Goldfarb, C.F., Rubinsky, Y.: The SGML Handbook. Oxford University Press, Oxford (1990)
Wielemaker, J.: SWI-Prolog SGML/XML parser. SWI, University of Amsterdam, Roetersstraat 15, 1018 (2005)
Seipel, D.: Processing XML-documents in prolog. In: Workshop on Logic Programming (WLP) (2002)
Seipel, D., Baumeister, J., Hopfner, M.: Declaratively querying and visualizing knowledge bases in Xml. In: Seipel, D., Hanus, M., Geske, U., Bartenstein, O. (eds.) INAP/WLP-2004. LNCS (LNAI), vol. 3392, pp. 16–31. Springer, Heidelberg (2005). https://doi.org/10.1007/11415763_2
Nogatz, F., Frühwirth, T.: From XML schema to JSON schema: translation with CHR. In: Proceedings of the 11th International Workshop on Constraint Handling Rules (2014)
Frühwirth, T.: Theory and practice of constraint handling rules. J. Log. Program. 37(1), 95–138 (1998)
Swift, T., Warren, D.S.: XSB: extending prolog with tabled logic programming. Theor. Pract. Log. Program. 12(1–2), 157–187 (2012)
Desouter, B., Van Dooren, M., Schrijvers, T.: Tabling as a library with delimited control. Theor. Pract. Log. Program. 15(4–5), 419–433 (2015)
Nogatz, F., Seipel, D.: Implementing GraphQL as a query language for deductive databases in SWI-Prolog using DCGs, quasi quotations, and dicts. In: Proceedings 30th Workshop on Logic Programming (WLP) (2016)
Seipel, D., Nogatz, F., Abreu, S.: Domain-specific languages in prolog for declarative expert knowledge in rules and ontologies. Comput. Lang. Syst. Struct. 51, 102–117 (2018). https://doi.org/10.1016/j.cl.2017.06.006
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2018 Springer Nature Switzerland AG
About this paper
Cite this paper
Nogatz, F., Kalkus, J. (2018). Declarative XML Schema Validation with SWI–Prolog. In: Seipel, D., Hanus, M., Abreu, S. (eds) Declarative Programming and Knowledge Management. WFLP WLP INAP 2017 2017 2017. Lecture Notes in Computer Science(), vol 10997. Springer, Cham. https://doi.org/10.1007/978-3-030-00801-7_12
Download citation
DOI: https://doi.org/10.1007/978-3-030-00801-7_12
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-00800-0
Online ISBN: 978-3-030-00801-7
eBook Packages: Computer ScienceComputer Science (R0)