diff --git a/gordon-plugin/src/main/kotlin/com/banno/gordon/Xml.kt b/gordon-plugin/src/main/kotlin/com/banno/gordon/Xml.kt index 53751b4..9f333c5 100644 --- a/gordon-plugin/src/main/kotlin/com/banno/gordon/Xml.kt +++ b/gordon-plugin/src/main/kotlin/com/banno/gordon/Xml.kt @@ -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) }