redundent / kotlin-xml-builder

A lightweight type safe builder to build xml documents in Kotlin
Apache License 2.0
151 stars 17 forks source link

Unsafe / raw data inside xml #53

Closed krzysztofsroga closed 1 year ago

krzysztofsroga commented 1 year ago

Hi! is there any way to insert raw data inside xml? Kotlin HTML dsl has unsafe{} block that allows me to insert raw data. Xml builder however, does not seem to have any option to skip escaping characters.

For example I'm trying to generate keyboard layouts and I want to set  as an attribute value

"key" {
    attributes(
        "code" to 108,
        "output" to ""
    )
}

The library generates xml:

<key code="108" output="&amp;#x0010;"/>

While I need it to generate:

<key code="108" output="&#x0010;"/>

Any workaround? If I could just insert whole <key code="108" output="&#x0010;"/> tag string as raw, I'd be happy as well but unfortunately it's also escaped.

redundent commented 1 year ago

I don't think there's a way to do it in its current state. I can see about adding an equivalent unsafe method to support it. I can probably get it done on Monday

krzysztofsroga commented 1 year ago

Thanks, that sounds great! For now I made a workaround of keeping a placeholder for all these values and replacing them at the end so I'm not held back by this for now. Unsafe block seems like a great addition overall!

redundent commented 1 year ago

I haven't had a chance to work on this yet. Sorry about that. Things are a bit crazy at work. Hopefully I'll get some time later today or tomorrow

redundent commented 1 year ago

Hey @krzysztofsroga , sorry it took so long but this is available in version 1.9.0 which I just published to Maven Central. Check out the readme for an example.

krzysztofsroga commented 1 year ago

I used the new version in my project and it works as expected. Thanks a lot!