我尝试使用
创建XMLdef builder = new groovy.xml.StreamingMarkupBuilder()
builder.encoding = "UTF-8"
def person = {
mkp.xmlDeclaration()
//mkp.declareNamespace('location':'http://someOtherNamespace')
person(id:100){
firstname("Jane")
lastname("Doe")
location.address("123 Main")
}
}
println builder.bind(person)
我收到了这个错误:
Caught: groovy.lang.GroovyRuntimeException: Namespace prefix: location is not bound to a URI
groovy.lang.GroovyRuntimeException: Namespace prefix: location is not bound to a URI
at MyTest$_run_closure1_closure2.doCall(MyTest.groovy:9)
at MyTest$_run_closure1.doCall(MyTest.groovy:6)
at MyTest.run(MyTest.groovy:12)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
我不需要命名空间。我只需要声明
答案 0 :(得分:4)
取决于您希望XML的样子(您没有在您的问题中说明):
如果你想:
<location><address>123 Main</address></location>
然后将location.address("123 Main")
更改为:
location {
address("123 Main")
}
如果你想:
<location address='123 Main'/>
然后将其更改为:
location( address:"123 Main" )