XmlSlurpur The prefix “something” for element “something:element” is not bound

♀尐吖头ヾ 提交于 2019-12-11 10:49:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!