2
创建XML我尝试使用没有命名空间
def 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)
我得到这个错误创建XML:
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)
我不需要命名空间。我只需要申报
然后纪念他的答案回复:http://blog.stackoverflow.com/2011/01/how-to-say-thanks-in-an-answer/ –