Groovy(特にXmlSlurper
:import groovy.xml.XmlUtil
)を使用してアンドロイドマニフェストからxmlを読み込もうとしていますが、私はGradleの下にいます。Groovyを使ったアンドロイドXMLの解析エラー
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.
他に何かお試しいただけますか?
をコールする必要がないように
ソリューションは、ルートタグに
xmlns:android="http://schemas.android.com/apk/res/android"
を追加されました。なぜ解析中に追加していますか? – RaoこんにちはRao、 "android:name"は私のXMLにあります。 XMLスニペットの先頭にxmlnx:android = ""のような宣言を追加する必要がありますか? –