LINQ to XML: Finding an element with a specific attribute



To simplify the problem statement, I am trying to search and see if a certain element is present in my file. My XML file is an AndroidManifest.xml file, used in Android apps. Specifically, I am searching for an element of type "uses-permission" with an element name of "android:name" and a value of "android.permission.INTERNET". Simple enough, right?


The query is,



IEnumerable<XElement> address =
from el in _rootElement.Elements( "uses-permission" )
where (string)el.Attribute( "android:name" ) == "android.permission.INTERNET"
select el;


The issue is that namespaces as in "android:name" can't be used within the query. So how do I make this query? I saw some complaining and suggestions elsewhere but can't incorporate them into my specific query.



<manifest xmlns:android="http://ift.tt/nIICcg" android:versionCode="1" android:versionName="1.0" package="com.app.myapp">

<uses-permission android:name="android.permission.INTERNET"/>

<application android:allowBackup="true" android:icon="@drawable/app_icon" android:label="App">

<activity android:configChanges="fontScale|keyboard|keyboardHidden" android:name="com.unity3d.player.UnityPlayerProxyActivity" android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>

No comments:

Post a Comment