我想從使用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 =「」這樣的聲明? –