问题
I am using XmlSlurper like so:
def slurper = new XmlSlurper().parseText(xmlObj.lensData).declareNamespace(something:'something')
when i slurp the following xml it give an error:
<something:Data>
<something:Requirements>
<something:Type>
<something:Value>T</something:Value>
<something:Label>TYP</something:Label>
</something:Type>
</something:Requirements>
</something:Data>
the error i get is:
The prefix "something" for element "something:Data" is not bound.. Stacktrace follows:
Message: The prefix "something" for element "something:Data" is not bound.
I don't really understand what t do to fix this. Any ideas?
回答1:
You need to use a different constructor on the XmlSlurper in order to get past parseText's validation/namespace awareness. Try:
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
来源:https://stackoverflow.com/questions/29265307/xmlslurpur-the-prefix-something-for-element-somethingelement-is-not-bound