Skip to content

Commit

Permalink
Add overload method for validate which accepts reader
Browse files Browse the repository at this point in the history
Such that a reader of choice can be passed (e.g. a buffered string reader) instead of the whole xml as a string
  • Loading branch information
johnksv committed Nov 18, 2022
1 parent 5f55b40 commit cb247c6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main/kotlin/no/ssb/kostra/barn/ValidationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.ssb.kostra.barn

import org.xml.sax.SAXParseException
import java.io.InputStream
import java.io.Reader
import java.io.StringReader
import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
Expand All @@ -16,8 +17,13 @@ object ValidationUtils {

@JvmStatic
fun validate(xml: String): Boolean {
return validate(StringReader(xml))

}
@JvmStatic
fun validate(xmlReader: Reader): Boolean {
return try {
getSchemaValidator().validate(StreamSource(StringReader(xml)))
getSchemaValidator().validate(StreamSource(xmlReader))
true
} catch (e: SAXParseException) {
false
Expand Down

0 comments on commit cb247c6

Please sign in to comment.