How to add XML namespaces #173
-
Hi folks, I'd like to add an XML namespace to the pkl file. Here's an example XML file.
How would I accomplish that? |
Beta Was this translation helpful? Give feedback.
Answered by
bioball
Feb 27, 2024
Replies: 1 comment
-
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.gitb.com/tdl/v1/"
["xmlns:gitb"] = "http://www.gitb.com/core/v1/"
}
}
output {
value = testSuite
renderer = new xml.Renderer {
converters {
[TestSuite] = (it) -> (xml.Element("testsuite")) {
attributes {
["id"] = it.id
}
} |> withGitbNs
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
citizenrich
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Typically, you'd do this by defining converters in your renderer. For example:
If you need to apply this namespace to many different types, you can share converter logic by introducing a mixin: