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/ –