pdvrieze / xmlutil

XML Serialization library for Kotlin
https://pdvrieze.github.io/xmlutil/
Apache License 2.0
363 stars 30 forks source link

Using namespace #193

Closed danzillo closed 6 months ago

danzillo commented 6 months ago

I would like to get the following line: <MyProject Version="1.0" Vendor="Me" xmlns:test="https://www.te.st/test"></MyPrject> But, when I am using that data class:

@Serializable
@XmlSerialName(value = "MyProject")
data class SimpleXML(
    @XmlSerialName(value = "Version")
    val version: Double = 1.0,
    @XmlSerialName(value = "Vendor")
    val vendor: String = "Me",
    @XmlSerialName(prefix = "test", namespace = "https://www.te.st/test")
    val url: String = "",

I have recive that: <MyProject Version="1.0" Vendor="Me" xmlns:test="url" test:https://www.te.st/test=""></MyPrject>

Found only one solution:

@Serializable
@XmlSerialName(value = "MyProject")
data class SimpleXML(
    @XmlSerialName(value = "Version")
    val version: Double = 1.0,
    @XmlSerialName(value = "Vendor")
    val vendor: String = "Me",
    @XmlSerialName(value = "xmlns:test")
    val url: String = "https://www.te.st/test",

Is it right?

Maybe you can tell me what to look for in the documentation?

pdvrieze commented 6 months ago

There is some sort of bug in the outputs (I guess the default name code is broken) but the intended way to achieve your outcomes is to use the @XmlNamespaceDeclSpec annotation and it will generate namespace declarations to your heart's content (it is a single text value, declarations are separated by ;, and are either just namespace urls or prefix=namespace pairs.

danzillo commented 6 months ago

thanks for the answer:3