在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):redundent/kotlin-xml-builder开源软件地址(OpenSource Url):https://github.com/redundent/kotlin-xml-builder开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):Kotlin XML BuilderThis library can be used to build xml documents from Kotlin code. It is based on the HTML builder described in the Kotlin docs It is designed to be lightweight and fast. There isn't any validation except to escape text to not violate xml standards. LicenseApache 2.0 UsageTo use in Gradle, simply add the Maven Central repository and then add the following dependency. repositories {
mavenCentral()
}
dependencies {
compile("org.redundent:kotlin-xml-builder:[VERSION]")
} Similarly in Maven: <dependencies>
<dependency>
<groupId>org.redundent</groupId>
<artifactId>kotlin-xml-builder</artifactId>
<version>[VERSION]</version>
</dependency>
</dependencies> Exampleval people = xml("people") {
xmlns = "http://example.com/people"
"person" {
attribute("id", 1)
"firstName" {
-"John"
}
"lastName" {
-"Doe"
}
"phone" {
-"555-555-5555"
}
}
}
val asString = people.toString() produces <people xmlns="http://example.com/people">
<person id="1">
<firstName>
John
</firstName>
<lastName>
Doe
</lastName>
<phone>
555-555-5555
</phone>
</person>
</people> class Person(val id: Long, val firstName: String, val lastName: String, val phone: String)
val listOfPeople = listOf(
Person(1, "John", "Doe", "555-555-5555"),
Person(2, "Jane", "Doe", "555-555-6666")
)
val people = xml("people") {
xmlns = "http://example.com/people"
for (person in listOfPeople) {
"person" {
attribute("id", person.id)
"firstName" {
-person.firstName
}
"lastName" {
-person.lastName
}
"phone" {
-person.phone
}
}
}
}
val asString = people.toString() produces <people xmlns="http://example.com/people">
<person id="1">
<firstName>
John
</firstName>
<lastName
>Doe
</lastName>
<phone>
555-555-5555
</phone>
</person>
<person id="2">
<firstName>
Jane
</firstName>
<lastName>
Doe
</lastName>
<phone>
555-555-6666
</phone>
</person>
</people> Processing InstructionsYou can add processing instructions to any element by using the xml("root") {
processingInstruction("instruction")
} <root>
<?instruction?>
</root> Global InstructionsSimilarly you can add a global (top-level) instruction by call xml("root") {
globalProcessingInstruction("xml-stylesheet", "type" to "text/xsl", "href" to "style.xsl")
} <?xml-stylesheet type="text/xsl" href="style.xsl"?>
<root/> DOCTYPEAs of version 1.7.4, you can specify a DTD (Document Type Declaration). xml("root") {
doctype(systemId = "mydtd.dtd")
} <!DOCTYPE root SYSTEM "mydtd.dtd">
<root/> Limitations with DTDComplex DTDs are not supported. Print OptionsYou can now control how your xml will look when rendered by passing the new PrintOptions class as an argument to
<root>
<element>value</element>
</root> as opposed to: <root>
<element>
value
</element>
</root>
Reading XMLYou can also read xml documents using the For more advanced consuming, check out konsume-xml. It includes many more features for consuming documents. Release NotesVersion 1.7.4
Version 1.7.3
Version 1.7.2
Version 1.7.1
Version 1.7POTENTIAL BREAKING CHANGES
Version 1.6.1
Version 1.6.0
BREAKING CHANGES
Version 1.5.4
Version 1.5.3
Version 1.5.2
Version 1.5.1
Version 1.5.0
BREAKING CHANGES
Version 1.4.5
Version 1.4.4
Version 1.4.3BREAKING CHANGES
Version 1.4.2
Version 1.4.1
Version 1.4BREAKING CHANGES
Version 1.3
Version 1.2
Version 1.1
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论