Skip to content

icmconsulting/clj-xml-validation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clj-xml-validation

A fork of the xml-validation library, created by rkday.

A Clojure library designed to wrap the Java libraries for XML schema validation. create-validation-fn takes a schema, and returns a function that takes an XML string and returns true (if the string is valid according to the schema) or false.

Improves on the original implementation of this library by:

  • Accept the schema to validate against using anything that the StreamSource constructor can handle (e.g an InputStream, Reader, File etc.) + URL
  • Returns a ValidationResult object, that encloses the validation errors

Install

Clojars Project

Usage

(require '[clj-xml-validation.core :as xmlv])
(def is-valid-xml? (xmlv/create-validation-fn (clojure.java.io/resource "example.xsd")))

(xmlv/valid? (is-valid-xml? "<foo><bar/></foo>"))
;; => true or false

(xmlv/errors (is-valid-xml? "<foo><bar/></foo>"))
;; => vector of {}'s - for example:
;; {:message "cvc-complex-type.2.4.a: Invalid content was found starting with element 'heading'. One of '{from}' is expected."
;;  :line-number 1
;;  :column-number 50
;;  :source "...SNIP..."}

;; Validating malformed xml throws an exception
(is-valid-xml? "<foo><bar/>")
;; => throws clojure.lang.ExceptionInfo

Building

lein do clean, test, install

License

Forked by Brendan Bates - ICM Consulting

Original Copyright © 2013 Rob Day

Distributed under the Eclipse Public License, the same as Clojure.

About

Clojure library for validating XML documents according to XSD schemas

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Clojure 100.0%