问题描述
$ b
def slurper = new XmlSlurper()。parseText(xmlObj.lensData).declareNamespace (东西:'东西')
当我啜饮下面的xml时,它给出了一个错误:
< something:Data>
< something:要求>
< something:Type>
< something:Value> T< / something:Value>
< something:Label> TYP< / something:Label>
< / something:Type>
< /东西:要求>
< / something:Data>
我得到的错误是:
元素something:Data的前缀something未被绑定。Stacktrace如下:
Message:元素something:Data的前缀something未绑定。
我不明白该如何解决此问题。
任何想法?
您需要在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
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?
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
这篇关于XmlSlurpur前缀“something”对于元素“something:element”不受约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!