我正在使用XmlSlurper:
def slurper = new XmlSlurper().parseText(xmlObj.lensData).declareNamespace(something:'something')
当我啜饮下面的xml时,它会出错:
<something:Data>
<something:Requirements>
<something:Type>
<something:Value>T</something:Value>
<something:Label>TYP</something:Label>
</something:Type>
</something:Requirements>
</something:Data>
我得到的错误是:
The prefix "something" for element "something:Data" is not bound.. Stacktrace follows:
Message: The prefix "something" for element "something:Data" is not bound.
我真的不明白要解决这个问题。 有什么想法吗?
答案 0 :(得分:0)
您需要在XmlSlurper上使用不同的构造函数才能超越parseText的验证/命名空间感知。尝试:
def slurper = new XmlSlurper(false, false).parseText(xmlObj.lensData).declareNamespace(something:'something')
http://docs.groovy-lang.org/docs/latest/html/gapi/groovy/util/XmlSlurper.html