This plugin packages the XML Processor as a Gradle plugin.
To use the XML Processor Plugin, you need to apply it in your build.gradle.kts
file and configure the xmlProcessor
extension as needed. Here's an example:
plugins {
id("io.github.tacascer.xml-processor")
}
xmlProcessor {
// configuration here
}
-
Create your input XML files:
sample.xsd
:<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.sample.com"> <xs:include schemaLocation="sample_1.xsd"/> <xs:element name="sample" type="xs:string"/> </xs:schema>
sample_1.xsd
:<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="sampleOne" type="xs:string"/> </xs:schema>
-
Configure the
xmlProcessor
extension in yourbuild.gradle.kts
file:xmlProcessor { processingSets { register("flatten") { input.add(file("path/to/your/sample.xsd")) output.set(layout.buildDirectory.dir("output")) filters.add(io.github.tacascer.flatten.IncludeFlattener()) } } }
This will create a task named
processXmlSetFlatten
. -
Run the task:
./gradlew processXmlSetFlatten
-
The
build/output/sample.xsd
file will now contain a flattened version of your XML schema<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.sample.com"> <xs:element name="sample" type="xs:string" /> <xs:element name="sampleOne" type="xs:string" /> </xs:schema>
You can define multiple processing sets, like so:
build.gradle.kts
:
xmlProcessor {
processingSets {
register("flatten") {
input.add(file("path/to/your/sample.xsd"))
output.set(layout.buildDirectory.dir("output"))
filters.add(io.github.tacascer.flatten.IncludeFlattener())
}
register("strip") {
input.add(file("path/to/your/sample.xsd"))
output.set(layout.buildDirectory.dir("output"))
filters.add(io.github.tacascer.namespace.NamespaceRemover())
}
}
}
This will create 2 tasks: processXmlSetFlatten
and processXmlSetStrip
.