redundent / kotlin-xml-builder

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

multiple namespaces #24

Closed keltik85 closed 4 years ago

keltik85 commented 5 years ago

Can this library produce this kind of xml with mutliple namespaces nested within each other?

<ns1:Person xmlns:ns1="foo:bar:baz:one" 
    xmlns:ns2="foo:bar:baz:two" 
    xmlns:ns3="foo:bar:baz:three">
        <ns1:name>John</ns1:name>
        <ns2:info>
            <ns3:age>123</ns3:age>
        </ns2:info>
</ns1:Person>
redundent commented 5 years ago

There isn't any special support for multiple namespaces but you can achieve it by just adding the namespaces as attributes on the element.

val person = xml("ns1:Person") {
    attribute("xmlns:ns1", "foo:bar:baz:one")
    attribute("xmlns:ns2", "foo:bar:baz:two")
    attribute("xmlns:ns3", "foo:bar:baz:three")

    "ns1:name"("John")
    "ns2:info" {
        "ns3:age"("123")
    }
}

That should work for now. I can add specific support for multiple namespaces

redundent commented 5 years ago

@keltik85 I don't know how I forgot about this but the library already supports multiple namespaces.

val person = xml("ns1:Person") {
    namespace("ns1", "foo:bar:baz:one")
    ....
}
keltik85 commented 5 years ago

Hi, thanks for your explanation @redundent .

How to add the dependency using maven?

redundent commented 5 years ago

I haven't used maven in a very long time but if memory serves me, the following should work.

You might need to add the jcenter repo if you don't already have it

<repositories>
    <repository>
        <id>jcenter</id>
        <url>https://jcenter.bintray.com/</url>
    </repository>
</repositories>

Then just add the dependency as normal

<dependency>
    <groupId>org.redundent</groupId>
    <artifactId>kotlin-xml-builder</artifactId>
    <version>1.5.2</version>
</dependency>