Skip to content

Commit

Permalink
Merge pull request #7 from Banno/fix-unsupported-feature
Browse files Browse the repository at this point in the history
Fix xmlpull unsupported feature
  • Loading branch information
joshschriever authored Nov 13, 2019
2 parents 4fb73af + 1a7d9e9 commit 689561c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion gordon-plugin/src/main/kotlin/com/banno/gordon/Xml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@ import java.io.StringWriter
internal fun xmlDocument(block: XmlSerializer.() -> Unit) = StringWriter().also {
XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null).newSerializer().run {
setOutput(it)
setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true)
indentOutput()
startDocument("UTF-8", null)
block()
endDocument()
}
}.toString()

private fun XmlSerializer.indentOutput() {
try {
setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true)
} catch (ignored: Throwable) {
try {
setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " ")
setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n")
} catch (ignored: Throwable) {
}
}
}

internal fun XmlSerializer.attribute(name: String, value: String) {
attribute("", name, value)
}
Expand Down

0 comments on commit 689561c

Please sign in to comment.