我想从使用Groovy的Android清单中读取xml(尤其是XmlSlurper
从import groovy.xml.XmlUtil
),并且我从Gradle中得到了低于。命名空间错误解析android xml与groovy
Error:The prefix "android" for attribute "android:name" associated with an element type "activity" is not bound.
导致该错误的代码如下:
def innerNodeTemplate = '''
<activity android:name=".activity.MyActivity"></activity>
'''
def activityNode = new XmlSlurper().parseText(innerNodeTemplate)
我曾尝试声明命名空间如下(from this existing answer)
activityNode = new XmlSlurper(false,false).parseText(innerNodeTemplate).declareNamespace(android:'android')
但后来我得到一个更加明确例外情况相同命名空间问题
Error:Cause: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 53; The prefix "android" for attribute "android:name" associated with an element type "activity" is not bound.
还有什么我可以尝试吗?
不存在在XML界这样的命名空间。为什么在解析时添加? – Rao
嗨饶,“android:name”是在我的xml。我是否需要在xml代码片段的开头添加像xmlnx:android =“”这样的声明? –