Skip to content

How to add XML namespaces #173

Closed Answered by bioball
citizenrich asked this question in Q&A
Discussion options

You must be logged in to vote

Typically, you'd do this by defining converters in your renderer. For example:

import "pkl:xml"

class TestSuite {
  id: String
}

testSuite: TestSuite = new {
  id = "Fun_Example"
}

output {
  value = testSuite
  renderer = new xml.Renderer {
    converters {
      [TestSuite] = (it) -> (xml.Element("testsuite")) {
        attributes {
          ["id"] = it.id
          ["xmlns"] = "http://www.gitb.com/tdl/v1/"
          ["xmlns:gitb"] = "http://www.gitb.com/core/v1/"
        }
      }
    }
  }
}

If you need to apply this namespace to many different types, you can share converter logic by introducing a mixin:

local withGitbNs: Mixin = new {
  attributes {
    ["xmlns"] = "http://www.gi…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by citizenrich
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants